【问题标题】:Adding a forward slash to the end of my URLs is breaking them在我的 URL 末尾添加正斜杠会破坏它们
【发布时间】:2011-07-25 19:51:24
【问题描述】:

我想在所有网址的末尾添加一个正斜杠......

目前,我网站上的示例链接是:<a href="/about/terms-of-use">

当我将其更改为:<a href="/about/terms-of-use/"> 时出现内部服务器错误

这是我的 htaccess:

AddType application/x-httpd-php .html 
AddType application/x-httpd-php .htm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html  [L]

为什么尾部的正斜杠会破坏 URL?

【问题讨论】:

    标签: .htaccess url mod-rewrite url-rewriting


    【解决方案1】:

    规则被打破了,因为(例如)你会得到类似的东西:使用条款/.html 试试这个:

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

    这将从请求中删除最后一个斜杠,然后将其重写到适当的文件中。

    猜你喜欢
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    相关资源
    最近更新 更多