我使用.htaccess
隐藏了所有页面的.php扩展名但是当某些类型的链接地址带有.php扩展名时,页面仍会以.php扩展名打开。我已尝试永久重定向.php页面到非php页面,例如example.com/about.php到example.com/about但它给我重定向循环错误。
这是我的.htaccess代码
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteRule ^products/(\d+)/([\d\w-\s]*)/([\d\w-\s]*)/([\d\w-\s]*)/?$ product_detail.php?id=$1&category=$3&parent_category=$2 [L,QSA]
</IfModule>
Options +MultiViews
ErrorDocument 404 /404.html
答案 0 :(得分:0)
您可以尝试将其添加到规则的顶部(仅在RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+(.*)\.php
RewriteRule ^ /%1 [L,R=301]
答案 1 :(得分:0)
将你的代码保存在root .htaccess:
中Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteRule ^products/(\d+)/([\d\w\s-]*)/([\d\w\s-]*)/([\d\w\s-]*)/?$ product_detail.php?id=$1&category=$3&parent_category=$2 [L,QSA]