【问题标题】:.htaccess change root folder and hide .html/.php extensions.htaccess 更改根文件夹并隐藏 .html/.php 扩展名
【发布时间】: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


【解决方案1】:

如果你只想隐藏扩展,可以看看这个

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

【讨论】:

  • 嘿骆驼,谢谢你的反馈,我现在就测试一下,再次感谢;)
  • @camel,所以我尝试添加您提交的这一行,我没有任何错误,这很好,但删除扩展标签并不快乐。这是一个奇怪的问题,请提供更多帮助。
猜你喜欢
  • 2013-03-13
  • 2012-12-30
  • 1970-01-01
  • 2014-03-31
  • 1970-01-01
  • 2020-05-12
  • 2014-03-29
  • 2017-10-06
  • 2018-06-30
相关资源
最近更新 更多