.htaccess更改根文件夹并隐藏.html/.php扩展名

.htaccess更改根文件夹并隐藏.html/.php扩展名,.htaccess,mod-rewrite,hide,root,.htaccess,Mod Rewrite,Hide,Root,我已经使用.htaccess更改了根文件夹,但是我还需要隐藏.html/.php扩展名,这就是我遇到的问题。我找到了隐藏扩展的替代方法,但并不像我想象的那么简单。以下是我到目前为止所做的工作>>> RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?cornellbond.co.uk$ RewriteCond %{REQUEST_URI} !^/liveSite/ RewriteCond %{REQUEST_FILENAME} !-f Rewr

我已经使用.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]
这是可行的,但当我向其中添加以下代码时,一切都停止工作

然后,我想隐藏我在here SOF上找到的.html/.php扩展,所以将这两个扩展组合在一起,我得到的只是错误

<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>

重新启动发动机
重写cond%{REQUEST_FILENAME}-f#如果请求的URL不是存在的文件
重写cond%{REQUEST_FILENAME}-而且它也不是一个存在的目录
RewriteCond%{REQUEST_FILENAME}\.html-f#但是当你把“.html”放在末尾时,它就是一个存在的文件
重写规则^(+)$$1\.html[QSA]#然后提供该文件
所以我的代码看起来都是这样的>>>

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>
重新编写引擎打开
重写cond%{HTTP_HOST}^(www.)?cornellbond.co.uk$
重写cond%{REQUEST_URI}^/现场/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/liveSite/$1
重写cond%{HTTP_HOST}^(www.)?cornellbond.co.uk$
重写规则^(/)?$liveSite/index.html[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}\.html-f
重写规则^(+)$$1\.html[QSA]

如果我能为此找到一份工作,我将不胜感激。我是不是说这对我来说都是新的,而且我还在学习=P再次感谢

如果你想隐藏扩展,也许看看这个

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

嘿,骆驼,谢谢你的反馈,我现在就测试一下,再次感谢;)@camel,所以我尝试添加您提交的这一行,我没有任何错误,这很好,但在删除扩展标记时没有乐趣。这是一个奇怪的问题,请多帮忙。嘿,马巴罗,我不明白你的答案,你能不能帮我把它分解一下,让它工作起来谢谢;)