2012-10-04 137 views
0

我已经使用.htaccess更改了根文件夹,但我也需要隐藏.html/.php扩展名,这是我遇到问题的地方。我找到了隐藏扩展名的替代方法,但并不像我想的那么简单。以下是我迄今所做>>>.htaccess更改根文件夹并隐藏.html/.php扩展名

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^(www.)?cornellbond.co.uk$ 

RewriteCond %{REQUEST_URI} !^/liveSite/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /liveSite/$1 
RewriteCond %{HTTP_HOST} ^(www.)?cornellbond.co.uk$ 
RewriteRule ^(/)?$ liveSite/index.html [L] 

这工作,但我下面的代码添加到它的一切停止工作。

然后我想要隐藏.html/.php扩展名我在这里找到了这个代码SOF,所以结合了这两个,所有我得到的是错误。

<IfModule mod_rewrite.c> 
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f  # if the requested URL is not a file that exists 
RewriteCond %{REQUEST_FILENAME} !-d  # and it isn't a directory that exists either 
RewriteCond %{REQUEST_FILENAME}\.html -f # but when you put ".html" on the end it is a file that exists 
RewriteRule ^(.+)$ $1\.html [QSA]   # then serve that file 

</IfModule> 

所以我的代码看起来像这样一起其中>>>

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^(www.)?cornellbond.co.uk$ 

RewriteCond %{REQUEST_URI} !^/liveSite/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /liveSite/$1 
RewriteCond %{HTTP_HOST} ^(www.)?cornellbond.co.uk$ 
RewriteRule ^(/)?$ liveSite/index.html [L] 

<IfModule mod_rewrite.c> 

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.+)$ $1\.html [QSA]   

</IfModule> 

如果我能得到一个变通为了这个,我将不胜感激。我说了这一切新的给我,我还在学习= P再次感谢

如果你只想隐藏扩展名可能看
+0

嘿mabarroso,我不明白你的答案,是否有可能你可以把它分解下来让我工作,谢谢;) –

回答

0

RewriteRule ^(.*)\.(php|html)$ /$1 [L,R] 
+0

嘿骆驼,感谢您的反馈,我会再次测试它,再次感谢;) –

+0

* @骆驼,所以我试着添加这条线,你提交,我没有错误,这是伟大的,但没有消除扩展标签的喜悦。这是一个奇怪的,请更多的帮助。* –