开发者

mass 301 redirect with .htaccess after site migration

I have a site that was created long ago using simple asp. It's a hotel site. It contains list-type pages and individual hotel pages. Currently my site is hosted on a Windows server which supports PHP too (but with no .htaccess support obviously). A few months ago I began to recode the entire site using php/mysql.

First I created the new list-type pages, I made the necessary 301 redirects on my hosting control panel, in order to keep the good search engine rankings. These pages has been nicely indexed by Google during the past few months, so they are OK.

Now I'm ready with recoding the remaining hotel pages (approx. 400), and now I want to migrate the entire site to an Apache server, which supports .htaccess.

There are two language versions of the hotel pages, English and German.

The old English ASP hotel pages were located in www.mysite.com/hotel/hotel-name.asp and I want to redirect them to www.mysite.com/hotel/hotel-name.php, so in this case only the file extension changes from .asp to .php.

The old German ASP h开发者_如何学Pythonotel pages were located in www.mysite.com/hotel/deutsch/hotel-name.asp and I want to redirect them to www.mysite.com/hotel/hotel-name.de.php, so in this case NOT only the file extension changes from .asp to .php, but file names and paths too.

My question is: how can I make the necessary mass redirects with .htaccess?

Thank you in advance.


This will work:

RewriteEngine On

# redirect German version
RewriteRule ^hotel/deutsch/(.+)\.asp$ http://www.mysite.com/hotel/$1.de.php [R=301,L]

# redirect English version
RewriteRule ^hotel/(.+)\.asp$ http://www.mysite.com/hotel/$1.php [R=301,L]

Order of rules is important here. First we match German versions and only then English pages (as pattern for URL for English pages is more broad and will also match German URLs which will end up in wrong redirect).


This should do the trick:

RewriteRule /hotel/deutsch/(.+?)\.asp /hotel/$1.de.php [R=301,L]
RewriteRule /hotel/(.+?)\.asp /hotel/$1.php [R=301,L]

Edit: Sorry, I missed that the German-language pages are *.de.php. I've updated the answer to use separate rewrites for the English and German pages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜