使用正则表达式重写规则以添加正斜杠

时间:2015-05-19 14:52:24

标签: regex apache .htaccess mod-rewrite url-rewriting

我想知道如何更改此网址:

https://www.mywebsite.com/online/param1/param2

https://www.mywebsite.com//online/param1/param2

或者进入

https://www.mywebsite.com/en/online/param1/param2

谢谢大家!

1 个答案:

答案 0 :(得分:3)

您可以在root .htaccess中使用此规则:

RewriteEngine On

# case 1
RewriteCond %{THE_REQUEST} !\s//
RewriteRule ^(online/.*)$ //$1 [R=302,NC,L,NE]

# case 2
RewriteRule ^(online/.*)$ /en/$1 [R=302,NC,L,NE]