Is it possible to apply different rewrite rules for different IP addresses using only one .htaccess file?
I have these rules:
RewriteEngine on
#RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /version/1.0/index.php?r=$1 [L]
RewriteRule ^(.*)$ /version/2.0/index.php?r=$1 [L]
Both of the last two rules work fine, and I can choose which one to enable. I want to somehow enable one rule for myself in order to work on development version, and other rule for production.
Can I use somehow IP address filtering for that? Is that even possible? Is there any other alternative solution so I can have both two rules enabled, one for my development and other one for production?
Try:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /version/1.0/index.php?r=$1 [L]
RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.123
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /version/2.0/index.php?r=$1 [L]
You need to duplicate the rewrite conditions. Each set of RewriteCond
's only apply to the immediately following RewriteRule
. So the first rule will get applied to everyone who isn't hitting the webserver from the IP address: 123.456.789.123
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With