views:

20

answers:

1

I'm trying to modify the following rewrite conditions so that only strings that begin with the number 4 are redirected to the process.php page as a variable:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /process.php?variable=$1 [L]

So the following

http://www.domain.com/4shopping

will be mapped to

http://www.domain.com/process.php?variable=4shopping

But the following will not

http://www.domain.com/shopping

The reason for this is that /shopping is just a normal page (served by Wordpress), but /4shopping is a code that should map on to the /process.php as a variable.

A: 

This will do:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(4[^/]*)$ /process.php?variable=$1 [L]

The regular expression means:

^      Start of string
(      Start capturing group (for $1)
 4     A literal "4"
 [^/]* Any character except "/", 0 or more times
)      End capturing group
$      End of string
Greg
Thanks for the excellent explanation. If the 4 condition isn't met, do you know how to then to switch back to a secondary condition, which for Wordpress is:RewriteRule . /index.php [L]I'm just getting errors if I run RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(4[^/]*)$ /process.php?variable=$1 [L]RewriteRule . /index.php [L]
Paul
Sorry that was a bit hashed up. What I was trying to say is that I need something that says "if 4 exists then /process.php?variable=$1 [L], otherwise /index.php [L]
Paul