如何解决如何为多个子目录制定 htaccess 重写规则
我有 3 个子目录,其中 index.PHP
文件具有相同的 url 参数:
example https://example.com/one/index.PHP?c=onestar
https://example.com/two/index.PHP?c=onestar
https://example.com/three/index.PHP?c=onestar
RewriteEngine On
options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.PHP -f
RewriteRule !.*\.PHP$ %{REQUEST_FILENAME}.PHP [QSA,L]
如何使其对 SEO 友好 https://example.com/one/index/onestar
。还有如何让它在未来动态添加多个目录,比如 https://example.com/four/index/onestar
解决方法
您可以在站点根目录 .htaccess 中使用此代码:
Options -MultiViews
RewriteEngine On
# http => https
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# /one/index/onestar => /one/index.php?c=onestar
RewriteRule ^([\w-]+)/index/([\w-]+)/?$ $1/index.php?c=$2 [L,NC,QSA]
# hide .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。