Topic: simple rule with multiple conditions
|

|
| Author |
|
mosco Newbie

Joined: 13 January 2005 Location: United States
Online Status: Offline Posts: 26
|
| Posted: 04 August 2008 at 4:49pm | IP Logged
|
|
|
Hi,
I need some help writing a rule to handle the following:
if url does not start with /- then redirect to /redirect.html
if url is /-[number string]/ or /-[number string]/index.html redirect to /redirect.html
otherwise do nothing
So for example mydomain.com/-123456/ or mydomain.com/-123456/index.html would get redirected, but mydomain.com/-123456/somethingelse.html or mydomain.com/-something/somedir would not get redirected.
Thanks!
|
| Back to Top |
|
| |
mosco Newbie

Joined: 13 January 2005 Location: United States
Online Status: Offline Posts: 26
|
| Posted: 05 August 2008 at 1:16pm | IP Logged
|
|
|
I've made some progress to get this to work but I'm stuck on the second rule (with a change needed from what I wanted to do at first), see below:
# if url is /-[number]/ or /-[number]/index.html go to redirect.html
RewriteRule /-(\d+)(/||/index\.html) /redirect.html [I,L]
This rule above works
but the rules below doesn't, the part I can't get right is to avoid redirecting if the / (site root) is called:
# if url doesn't:
# start with /-
# or start with /login
# or is not /
# then go to redirect.html
RewriteRule ^(?!(?:/-|/login)).* /redirect.html [I,L]
How can I get this rule above to also ignore / requests?
Would really appreciate some help,
Thanks.
|
| Back to Top |
|
| |
mosco Newbie

Joined: 13 January 2005 Location: United States
Online Status: Offline Posts: 26
|
| Posted: 05 August 2008 at 1:21pm | IP Logged
|
|
|
For the second rule I am also trying, which seems to do what I want:
RewriteRule ^(?!(?:/-|/login)).*|/ /redirect.html [I,L]
Is this the correct way of doing this?
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7598
|
| Posted: 07 August 2008 at 7:12pm | IP Logged
|
|
|
All these could be handled with the single rule:
# if url is /-[number]/ or /-[number]/index.html go to redirect.html
# if url doesn't:
# start with /-
# or start with /login
# or is not /
# then go to redirect.html
RewriteRule /(?:-\d+/(?:index\.html.*)?|(?!-).*|login(?:$|/.*)) /redirect.html [I,L]
|
| Back to Top |
|
| |
|
|
If you wish to post a reply to this topic you must first login
If you are not already registered you must first register
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum
|