Please help me! I have moved my entire site from ASP to PHP and need a 301 Redirect that will send the old asp-page to the new php-page (with the same name - except from the php-extension):
The subdomains are “virtual”. Meaning that the subdomains don’t really exist - you are send to the same page but in the code I show the text (language) that correspond to the “subdomain” in the url. Therefore I hope it would be possible to keep the url in the redirect. Is it possible?
Aw, come on now! Don’t you expect that andreasa has at least one character in the name of his/her asp files? DON’T use *, use + to require at least one character! Otherwise, :tup:
[ – start a character class
a-z – any character between ‘a’ and ‘z’ (including)
A-Z – any character between ‘A’ and ‘Z’ (including)
0-9 – any digit between 0 and 9 (including)
] – end of character class
– repeat characters from the character class zero or more times
You can’t mix RewriteCond with RedirectMatch; it won’t work as they are two different systems.
That being said, RedirectMactch cannot help you here at all, since the first part (the from part) is specified using the path only (not the full URL) and in the next part (the to part) you need to use a full URL including schema.
So, using RedirectMatch everything will be redirected to one domain, no option to send it to different domains.
What you’re looking for here is RewriteCond together with RewriteRule:
RewriteEngine On
RewriteRule (.*)default\\.asp$ http://%{HTTP_HOST}$1index.php [L,R=301]
RewriteRule (.*)\\.asp$ http://%{HTTP_HOST}$1.php [L,R=301]
Because of the %{HTTP_HOST} in the right side of those rules it will redirect to the (sub)domain that was requested.
Lastly, please take a look at the article linked in dklynn’s signature, and make those regular expressions more sensible than using the :kaioken:EVERYTHING:kaioken: atom (.*) Yes - it’s really as bad as I make it out to be!
As for the subdomains, these are probably served from a different directory where your .htaccess isn’t applied. Make sure the .htaccess works first and then copy it to the directories where the subdomains are placed.
Lastly, (.*) is not a good way to write regular expressions, since it can match nothing or everything, and can cause of lot of problems when used incorrectly. I’m assuming it works for you, but I’d nonetheless recommend you use something more sensible like [a-zA-Z0-9_-]+ to match only characters, digits, underscores and dashes. Of course the actually regular expression depends on what path names are possible.
Probably not - BECAUSE each subdomain is treated as a separate domain. Saying that, it must be registered with your local DNS server just to receive the request.