How to remove // from URL using htaccess

牧云@^-^@ 提交于 2019-12-25 08:09:11

问题


How to remove / from URL if they appear twice or thrice.
Like:

 www.site.com/mauritius_holiday_rentals/search//2/Pool-Villa

should become

 www.site.com/mauritius_holiday_rentals/search/2/Pool-Villa

and

www.site.com/mauritius_holiday_rentals/search///Beach-Villa

should become

www.site.com/mauritius_holiday_rentals/search/Beach-Villa


回答1:


You can use RedirectMatch directive With Regex, so If an additional forword slash was added accidently to the url ,then you have a chance to make it optional or permanently delete it from the url.

 RedirectMatch 301 ^/mauritius_holiday_rentals/search//?/?/2/(.*)$ /mauritius_holiday_rentals/search/2/$1


 RedirectMatch 301 ^/mauritius_holiday_rentals/search//?/?/(.*)$ /mauritius_holiday_rentals/search/$1 



回答2:


Try this:-

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www.example.com/mauritius_holiday_rentals/search/$
RewriteRule (.*) http://www.example.com/mauritius_holiday_rentals/search///$1 [R=301]


来源:https://stackoverflow.com/questions/23581984/how-to-remove-from-url-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!