【问题标题】:Rewrite not working for some url in htaccess重写不适用于 htaccess 中的某些 url
【发布时间】:2015-02-11 12:09:53
【问题描述】:

对于某些 URL,我的 htaccess 无法正常工作。我只想将文件的扩展名如php重写为html。但它不起作用。当我输入像“http://www.example.com/myfile.php”和“http://www.example.com/myfile.html”这样的 URL 时,两个 url 都在工作。但我只想将 myfile.php 重写为 myfile.html。

我的 htaccess 重写规则是:-

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Options -Indexes
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^index\.php$ "http\:\/\/example\.com\/" [R=301,L]

Header unset Pragma
FileETag None
Header unset Last-Modified
Header unset ETag

RewriteRule ^myfile.html$ myfile.php [QSA,L]

ServerSignature Off

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    将此添加到您的 .htaccess 文件中。

    RewriteCond %{THE_REQUEST} \ /+myfile\.php(\s|\?) [NC]
    RewriteRule ^ /myfile.html [R=301,L]
    
    RewriteRule ^myfile\.html$ /myfile.php [NC,L]
    

    如果用户尝试直接访问myfile.php,第一条规则负责重定向到myfile.html。

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 2018-03-28
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 2017-04-17
      相关资源
      最近更新 更多