如何解决复杂的 .htaccess 重写
-
https://www.example.com/forum/news/state-news/archive 到 https://www.example.com/forum/news/state-news?archive=yes
-
https://www.example.com/forum/news/state-news/city-news/archive 到 https://www.example.com/forum/news/state-news/city-news?archive=yes
-
https://www.example.com/forum/news/state-news/city-news/area-news/archive 到 https://www.example.com/forum/news/state-news/city-news/area-news/?archive=yes
我尝试过的 htaccess 文件是:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(core/libraries/|includes|core/includes|core/vb|core/vb5|core/admincp|core/modcp) index.PHP?routestring=relay/404 [END]
RewriteRule ^css.PHP$ core/css.PHP [NC,L]
RewriteRule ^install/ core/install/ [NC,L]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|png|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.PHP?routestring=$1 [L,QSA]
</IfModule>
解决方法
以下列方式拥有您的 htaccess 规则文件。我在您的问题中专门介绍了您显示的 3 个 URL。请确保您使用这些规则并确保在测试您的 URL 之前清除浏览器缓存。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(core/libraries/|includes|core/includes|core/vb|core/vb5|core/admincp|core/modcp) index.php?routestring=relay/404 [END]
RewriteRule ^css\.php$ core/css.php [NC,L]
####I have commented below rule that doesn't make sense,since NO right part in it only condition is mentioned.
####RewriteRule ^install/core/install/ [NC,L]
###New rules added by me to handle 3 different URLs shown by OP in question.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(forum/news/state-news(?:(?:/city-news(?:area-news))))/(archive)/?$ $1?$2=yes [NC,QSA,L]
RewriteCond %{REQUEST_URI} !\.(gif|jpg|jpeg|png|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?routestring=$1 [L,QSA]
</IfModule>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。