Forum Moderators: phranque

Message Too Old, No Replies

url rewrite regex help ?

         

PHPycho

6:00 am on May 14, 2008 (gmt 0)

10+ Year Member



Hello forums
I have some problem regarding regex in url rewriting.
case:
.htaccess
Options -Indexes
Options +FollowSymlinks

RewriteEngine on
RewriteRule ^admin/(.*)$ admin_$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Main URL rewriting.
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Everything works fine except for admin part.
When admin/any_text comes in url, it routes to admin_any_text. but i want resitriction in some cases as i have folder structure for admin as:

-admin
--js
--themes
---default
----images
----css

I want to modify rule: RewriteRule ^admin/(.*)$ admin_$1 [L] so that it doesn't rewrite for admin/js,admin/themes
How to accomplish this ?
Thanks in advance for the valueable suggestions.

dublinmike

11:53 am on May 14, 2008 (gmt 0)

10+ Year Member



Hi there,

Instead of:


RewriteRule ^admin/(.*)$ admin_$1 [L]

which matches any (.) character after the "admin/" bit, try:


RewriteRule ^admin/([^/]*)$ admin_$1 [L]

this will match "admin/" and then any characters as long as they don't contain a '/'. This should eliminate rewrites to admin/js/, admin/themes/ &c.

jdMorgan

3:10 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Comment: Use the "+" quantifier unless you also want to rewrite "admin/" to "admin_" -- that is, admin/<blank> to admin_<blank>

RewriteRule ^admin/([^/]+)$ admin_$1 [L]

Jim