简体   繁体   中英

.htaccess 301 permanent redirect rule

I have this url structure right now.

http://example.com/weather/in-city_name

which I want to permanently redirect to

http://example.com/city_name/weather

Here is what I'm writing to the .htaccess file using this reference

RedirectMatch ^/weather/(.*)$ http://example.com/$1/weather

But this doesn't work.

In my condition city_name is dynamic and manual entry is not possible.

Any suggestion about how to achieve the desire result would be great.

You can use this .htaccess :

RewriteEngine on 
RewriteRule ^weather/in-(.+)/?$ /$1/weather   [R=301,NC,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM