[英]How to remove part of the URL and redirect using mod_rewrite in htaccess?
I would like to remove part of the url of my Joomla site and redirect to another url for example 我想删除我的Joomla网站的部分网址,例如重定向到另一个网址
www.example.com/xxx/yyy/zzz/FAQ www.example.com/xxx/yyy/zzz/FAQ
www.example.com/123/456/FAQ www.example.com/123/456/FAQ
to 至
www.example.com/FAQ www.example.com/常见问题解答
I'm very new to mod_rewrite in .htacesss 我对.htacesss中的mod_rewrite很陌生
what RewriteRule can I write to achive this 我可以写些什么RewriteRule来达到这个目的
thank you 谢谢
Try this in root/htaccess 在root / htaccess中尝试一下
RewriteEngine On
RewriteCond %{THE_REQUEST} /xx/yy/zz/([^\s]+) [NC]
RewriteRule ^ /%1? [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /xx/yy/zz/$1 [NC,L]
And the same rule can be used to rewrite /123/456/faq to /123/456/FAq , just change the rewrite target and the pattern in first Rewritecond. 并且可以使用相同的规则将/ 123/456 / faq重写为/ 123/456 / FAq,只需在第一个Rewritecond中更改重写目标和模式即可。
$1 is part of the regex in rewrite rule, its the part matched between (.+) ,it contains uri. $ 1是重写规则中正则表达式的一部分,其与(。+)之间匹配的部分,它包含uri。
Thank you, after I tried I finally got it working 谢谢,我尝试了之后终于成功了
this is my solution 这是我的解决方案
RewriteEngine On
RewriteRule ^.*/FAQ$ /FAQ [L,R=301]
by doing this I remove everything between the URL and FAQ 通过这样做,我删除了URL和FAQ之间的所有内容
www.abc.com/SOMETHING/SOMETHING2/FAQ www.abc.com/SOMETHING/SOMETHING2/常见问题解答
and redirect the URL to 并将URL重定向到
www.abc.com/FAQ www.abc.com/常见问题
I also found a nice tool to test the mod_rewrite code http://htaccess.madewithlove.be/ 我还找到了一个不错的工具来测试mod_rewrite代码http://htaccess.madewithlove.be/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.