Rewrite Rule - If the incoming request does not consist of certain characters, then rewrite it to a different url
How do I create a rule that checks if an incoming request has certain terms, if not, then redirect to a different URL?
For example, I have a website my.example.com
. If an incoming url my.example.com/login
, then it should fulfill this request. If it is something else (not login
), the request should be redirected to your.example.com
. For instance,
-
my.example.com/login2
should redirect toyour.example.com/login2
-
my.example.com/nologin
should redirect toyour.example.com/nologin
-
my.example.com/getname
should redirect toyour.example.com/getname
And, of course, if he
-
my.example.com/login
should redirect tomy.example.com/login
How do I use RewriteRule and mod_rewrite to achieve this?
a source to share
I know this is not exactly what you asked for, but do it using .htaccess to route all requests (valid or not) to a single file and then use server side scripts (like PHP in my case) to switch valid parameters, intercepting everything else by default, which redirects to a different url.
eg. this is:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
sends anything that is not a request for the actual file or directory index.php
a source to share