【问题标题】:Add slashes to .php file extensions only仅在 .php 文件扩展名中添加斜杠
【发布时间】:2021-05-04 09:29:38
【问题描述】:

我的 htaccess 代码在所有 URL 的末尾添加了一个斜杠,但我只想在以 .php 文件扩展名结尾的文件中添加斜杠,我该怎么做?

我的 htaccess 代码:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

【问题讨论】:

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


    【解决方案1】:

    请您尝试以下操作。仅使用所示示例编写。请确保在测试您的 URL 之前清除浏览器缓存

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} \.php$ [NC,OR]
    RewriteCond %{REQUEST_URI} ^/seo$ [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [NC,L]
    

    【讨论】:

    • 我会为这个问题打开另一个线程。你已经回答了我问的问题。
    • @ardacar,当然,干杯和快乐学习。
    猜你喜欢
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2018-04-09
    相关资源
    最近更新 更多