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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

This of any help?

.htaccess mod_rewrite - how to exclude directory from rewrite rule

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.