htaccess 301重定向无法正常工作

Sum*_*ani 2 php apache .htaccess mod-rewrite redirect

我已经通过htaccess重写了URL,现在我想将该URL重定向到另一个URL.


下面是我的重写规则,我用它来做短网址

RewriteRule ^([a-zA-Z0-9_-]+)$ modules/pages/content.php?page_url=$1 [NC,L]
Run Code Online (Sandbox Code Playgroud)

这工作正常,我可以访问像..

http://www.domain.com/example-page
Run Code Online (Sandbox Code Playgroud)


现在我想将http://www.domain.com/example-pageURL 重定向到http://www.domain.com/product/features/example-page

我的htaccess重定向代码是..

redirect 301 /example-page http://www.domain.com/product/features/example-page
Run Code Online (Sandbox Code Playgroud)

这段代码正在运行,但我遇到了问题.

当我打开URL时,http://www.domain.com/example-page它会重定向到http://www.domain.com/product/features/example-page?page_url=example-page

而不是它.我希望它重定向到http://www.domain.com/product/features/example-page.

请帮我解决这个问题.

Jon*_*Lin 7

您需要坚持使用mod_rewrite,而不是将mod_rewrite指令与mod_alias指令(Redirect 301)混合使用.重写规则路由到之前content.php,添加:

RewriteRule ^example-page$ http://www.domain.com/product/features/example-page [L,R=301]
Run Code Online (Sandbox Code Playgroud)