【问题标题】:Can't Add Slash with .htaccess无法使用 .htaccess 添加斜线
【发布时间】:2010-10-27 23:45:35
【问题描述】:

我有一个网站,上面有一些 html 文件。其中之一是contact.html。这是我的 .htaccess,我在可以使用 site.com/contact 而非 site.com/contact/ 寻址页面时遇到问题。 (注意结束斜线。)解决方法是什么?

RewriteEngine On

# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_fileNAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_fileNAME} !-f
# then add .html to get the actual filename
rewriterule (.*) /$1.html [L]

【问题讨论】:

    标签: apache url .htaccess apache2 backslash


    【解决方案1】:

    代替:

    rewriterule (.*) /$1.html [L]
    

    试试:

    RewriteRule ^([^/]*)/?$ /$1.html [L]
    

    【讨论】:

    • 修复了它。我只需要确保使用 src、href 和图像链接查找所有相对路径并将它们切换到固定路径。
    【解决方案2】:
    RewriteRule ^([^/]*)/?$ $1.php [L]
    

    在我的情况下,我将删除 $1 之前的斜线并且它有效!我很高兴从您的评论中学到很多东西。

    【讨论】:

      猜你喜欢
      • 2016-08-24
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      • 1970-01-01
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-28
      相关资源
      最近更新 更多