1

I need help with my mod_rewrite for a site im currently working on.

Let's say I have this site http://example.com

And I want to be able to make any value after the / to route to page.php like below

http://example.com/value1

http://example.com/value2

to point to

http://example.com/page.php?id=value1

http://example.com/page.php?id=value2

,respectively.

But, not route to that page when im pointing to "admin"

http://example.com/admin/

I've tried

RewriteEngine on
RewriteCond $1 !^(admin)
RewriteRule ^(.*)$ /page.php?id=$1 [L]

But it isn't working. Any thoughts?

Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
Mark
  • 11
  • 1

2 Answers2

3

$1 is not available at the time of the Condition. I believe what you are looking for is close to:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^admin/.*
RewriteRule ^(.*)$ page.php?id=$1 [L]

this rule causes everything not starting with admin/ to go to /page.php. I don't believe the %{param} is optional. Using RewriteBase / means you do not to have prepend / on /admin and /page.php; it may actually fault if you use /page.php instead of page.php

If you have means of accessing the server values, then the final rule can be:

RewriteRule . page.php [L]

You can find the called url in the REQUEST_URI

ppostma1
  • 3,616
  • 1
  • 27
  • 28
  • just noticed you were correct in the $1, the rule is processed first then conditions checked after. They may refer to the results of the reg-ex – ppostma1 Aug 08 '11 at 21:30
0

This of any help?

.htaccess mod_rewrite - how to exclude directory from rewrite rule

Community
  • 1
  • 1
Jonathan
  • 5,953
  • 1
  • 26
  • 35