【发布时间】:2012-10-04 22:30:16
【问题描述】:
我已经使用 .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再次感谢
【问题讨论】:
-
嘿 mabarroso,我不明白你的回答,你能不能把它分解给我让它工作谢谢 ;)
标签: .htaccess mod-rewrite hide root