【发布时间】:2020-05-17 07:14:45
【问题描述】:
我下面的 .htaccess 代码给出了意想不到的结果。请通过参考预期结果与输出结果来帮助我解决此问题。
<IfModule mod_rewrite.c>
Redirect /main-page https://example.com/new-main-page
Redirect /main-page/sub-page1 https://example.com/new-main-page/new-sub-page1
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
## Added as per WP-1252 ##
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
</IfModule>
预期行为:
请求 1:https://sample.com/main-page 重定向到 https://example.com/new-main-page
请求 2:https://sample.com/main-page/sub-page1 重定向到 https://example.com/new-main-page/new-sub-page1
请求 3:https://sample.com/main-page/sub-page2 重定向到 https://sample.com/page-not-found
输出结果:
请求 1:https://sample.com/main-page 重定向到 https://example.com/new-main-page(预期行为)
请求 2:https://sample.com/main-page/sub-page1 重定向到 https://example.com/new-main-page/new-sub-page1(预期行为)
请求 3:https://sample.com/main-page/sub-page2 重定向到 https://example.com/new-main-page/sub-page2(意外行为。为什么?)
【问题讨论】:
标签: wordpress apache .htaccess mod-rewrite mod-alias