【问题标题】:Simple rewriting rule简单的重写规则
【发布时间】:2014-12-11 16:06:04
【问题描述】:

好吧,也许我是垃圾,但我的简单重写 .htacces 规则不起作用。我只想在我的网站上例如 www.mysite.com/something.html 将规则重写为 www.mysite.com/something 。我只想删除 .html 并从文件 something.html 中获取内容

现在我的 .htacces 文件中有这个,但无法正常工作:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
AddType application/x-httpd-php5 .htm .html

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite rewrite


    【解决方案1】:

    您需要另一个规则来重定向.html

    RewriteEngine On
    
    # To externally redirect /dir/file.php to /dir/file
    RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
    RewriteRule ^ /%1 [R=302,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L,QSA]
    AddType application/x-httpd-php5 .htm .html
    

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 2011-11-09
      • 2014-02-04
      • 2016-09-14
      相关资源
      最近更新 更多