Domanda

I have a strange issue happening after a WordPress Migration.

After setting up a new domain, I used:

RewriteRule ^blog/(.*) http://www.newdomain.com/blog/$1 [R=301,L]

to redirect all blog posts to the new domain. This works perfect.

I now found some urls such as

http://www.olddomain.com/blog/directory/file/ that I want to send to http://www.newdomain.com/blog/directory/

Directory is a variable and file is a variable.

Is it possible to create an htaccess that keeps my original Rule, but also creates another rule to handle the the file redirect.

È stato utile?

Soluzione

This should work

RewriteRule ^blog/(.*)/(.*)/? http://www.newdomain.com/blog/$1/ [R=301,L]
RewriteRule ^blog/(.*) http://www.newdomain.com/blog/$1 [R=301,L]

It will keep your original rule and will rewrite http://www.olddomain.com/blog/directory/file/ to http://www.newdomain.com/blog/directory/

The /? means that the last / is optional i.e. it will redirect http://www.olddomain.com/blog/directory/file/ and http://www.olddomain.com/blog/directory/file to http://www.newdomain.com/blog/directory/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top