: Why is this mod_rewrite redirecting my domain? I'm trying to redirect all URLs past the "/" of my domain to an old.mysite.com version, but leave the mysite.com itself alone. For example, "mysite.com"
I'm trying to redirect all URLs past the "/" of my domain to an old.mysite.com version, but leave the mysite.com itself alone.
For example, "mysite.com" -> "mysite.com", but "mysite.com/some-url" -> "old.mysite.com/some-url". Here's what I have now:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.+)$
RewriteRule /(.*) archived.example.com/
But it's redirecting "mysite.com" -> "old.mysite.com". How can I modify this so that the core domain doesn't get redirected, but only when there are URL bits past the ".com/" so to speak?
More posts by @Lee4591628
1 Comments
Sorted by latest first Latest Oldest Best
The RewriteCond %{REQUEST_URI} ^/(.+)$ matches all characters after the /
(.+) is a regular expression that matches any character.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/[a-zA-Z0-9/-]+$
RewriteRule /(.*) archived.example.com/
The above might do it, but I'm not very good with regular expressions.
[a-zA-Z0-9/-]+ will match a series of any of the characters in the brackets following the trailing /.
I use RegExLib as my cheat-sheet. It'll also let you test regular expressions against a source (to see what matches).
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.