Mobile app version of vmapp.org
Login or Join
Lee4591628

: 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"

@Lee4591628

Posted in: #Apache #ModRewrite

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Lee4591628

1 Comments

Sorted by latest first Latest Oldest Best

 

@Martha676

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).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme