Link to home
Start Free TrialLog in
Avatar of Andreasa2010
Andreasa2010

asked on

htaccess: Redirect with virtual subdomains

Please help me! I have moved my entire site from ASP to PHP and need a 301 Redirect that will send the old asp-pages to the new php-pages (with the same name - except from the php-extension):

http://www.mysite.com/test.asp --> http://www.mysite.com/test.php

And default.asp should go to index.php:

http://www.mysite.com/folder/default.asp --> http://www.mysite.com/folder/index.php

So fare this works fine:

RedirectMatch permanent (.*)default\.asp$ http://www.mydomain.com$1index.php
RedirectMatch permanent (.*)\.asp$ http://www.mydomain.com$1.php

BUT, it also needs to work with virtual subdomains:

http://whatever.mysite.com/folder/test.asp --> http://whatever.mysite.com/folder/test.php

This is as fare as I got:

RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RedirectMatch permanent (.*)default\.asp$ http://%1.mydomain.com$1index.php
RedirectMatch permanent (.*)\.asp$ http://%1.mydomain.com$1.php

But is is not working...
Avatar of Dushyant Sharma
Dushyant Sharma
Flag of India image

try this

RedirectMatch ^/(.*)\.asp$ /dept/$1.php
ASKER CERTIFIED SOLUTION
Avatar of Dushyant Sharma
Dushyant Sharma
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andreasa2010
Andreasa2010

ASKER

Thanks!

I actually - with a litle help - got this to work:

RewriteEngine On
RewriteRule (.*)default\.asp$ http://%{HTTP_HOST}/$1index.php [L,R=301]
RewriteRule (.*)\.asp$ http://%{HTTP_HOST}/$1.php [L,R=301]

But you get the points!