How to redirect multiple similar URLs with one que

2019-09-08 18:44发布

I currently have lots of URLs that look like this:

http://www.domain.com/classes-dallas-tx.html

I need to change all URLs to the following:

http://www.domain.com/classes-in-dallas-tx.html

I just need to add the "in" into every URL that doesn't have it right now.

Is there one query I can use for the .htaccess file that will take care of all the URLs for me? I'm planning on using the 301 redirect.

Thanks!

1条回答
一纸荒年 Trace。
2楼-- · 2019-09-08 19:10

Try:

RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html

Or

RewriteEngine On
RewriteRule ^/?([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html [L,R=301]

in the htaccess file in your document root.

查看更多
登录 后发表回答