您可以让我知道 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。请确保您使用这些规则,并确保在测试您的网址之前清除浏览器缓存。
<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>
关于apache - 复杂的 .htaccess 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67115892/