url rewrite regex help ??

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

url rewrite regex help ??

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: url rewrite regex help ??

Post by s.dot »

A stab in the dark here..

Code: Select all

RewriteRule ^admin/[^js|themes]?(.*)$ admin_$1 [L]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: url rewrite regex help ??

Post 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)
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: url rewrite regex help ??

Post by PHPycho »

I had found the solution as:

Code: Select all

RewriteRule ^admin/(?!(js|theme)($|/))(.*) admin_$3 [L]
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: url rewrite regex help ??

Post 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.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: url rewrite regex help ??

Post 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.
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: url rewrite regex help ??

Post 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
Post Reply