[英]Remove last Path from URL using .htaccess
I need to create a RewriteRule on my .htaccess file which removes the Path ("page-2") if it's included at the end of the URL. 我需要在我的.htaccess文件上创建一个RewriteRule, 如果它包含在URL的末尾,它将删除Path(“page-2”)。 So for example:
例如:
http://myhost.com/path/page-2
should redirect to: 应重定向到:
http://myhost.com/path
I've found a similar solution on SO: 我在SO上找到了类似的解决方案:
RewriteEngine On
RewriteRule ^([^/.]+)/?$ /$1/page-2/ [L]
However it does not work for me. 但它对我不起作用。 No redirection happens.
没有重定向发生。 Any help?
有帮助吗?
You need to have this rule: 你需要有这个规则:
RewriteEngine On
RewriteRule ^(.+?)/page-2/?$ /$1 [L,NC,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.