Page 1 of 1

url rewrite regex help ??

Posted: Wed May 14, 2008 1:00 am
by PHPycho
Hello forums
I have some problem regarding regex in url rewriting.
case:
.htaccess

Code: Select all

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.

Re: url rewrite regex help ??

Posted: Wed May 14, 2008 1:06 am
by s.dot
A stab in the dark here..

Code: Select all

RewriteRule ^admin/[^js|themes]?(.*)$ admin_$1 [L]

Re: url rewrite regex help ??

Posted: Wed May 14, 2008 1:45 am
by PHPycho
No it didnt work.
I tested with following results:

Code: Select all

http://127.0.0.1/mysite/admin/personnels => url = admin_ersonnels [X] (P is ommitted)
http://127.0.0.1/mysite/admin/login => url = admin_login [OK] (its ok)
http://127.0.0.1/mysite/admin/js => url = admin_js [X] (assumed to be admin/js as it is)
http://127.0.0.1/mysite/admin/themes => url = admin_themes [X] (assumed to be admin/themes as it is)

Re: url rewrite regex help ??

Posted: Sat May 17, 2008 10:53 pm
by PHPycho
I had found the solution as:

Code: Select all

RewriteRule ^admin/(?!(js|theme)($|/))(.*) admin_$3 [L]

Re: url rewrite regex help ??

Posted: Fri Jun 13, 2008 1:06 am
by PHPycho
Hello forums!!
I am reopening this thread because this regex didn't worked in live server
though it worked perfectly in localhost.
In the live server apache is V1.3. I think the regex is not running its because of assertion type.
The error shown by the server is compilation error.
Is there any alternatives for this regex that doent use assertion.

Thanks in advance for the valueable help.

Re: url rewrite regex help ??

Posted: Fri Jun 13, 2008 2:26 am
by prometheuzz
PHPycho wrote:Hello forums!!
I am reopening this thread because this regex didn't worked in live server
though it worked perfectly in localhost.
In the live server apache is V1.3. I think the regex is not running its because of assertion type.
The error shown by the server is compilation error.
Is there any alternatives for this regex that doent use assertion.

Thanks in advance for the valueable help.
I have little knowledge about Apache's rewrite mod, but someone who does possess that knowledge might not answer you because of the lack of useful information: you only provided the version of the production server, not the test server. You did not post the regex you are using (one can assume it's the last one you've posted, but still, for clarity it should be posted again). And lastly, you say that the server produced "an error". At least copy and paste the exact error message you see on your screen: "an error" can mean an awful lot.

Good luck.

Re: url rewrite regex help ??

Posted: Fri Jun 13, 2008 6:46 am
by GeertDD
Here is one thing you should know about Apache: "Apache 1.3 speaks POSIX Extended RegEx while Apache 2.x understands PCRE".

Source: http://rewrite.drbacchus.com/rewritewik ... expression