small reguller express issue

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

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

small reguller express issue

Post by itsmani1 »

Here is my express:

Code: Select all

 
RewriteEngine on
RewriteRule ^shop/(.*)/ index.php [nc]
what's is happening is its converting every .com/shop/anything/ to index.php

its transferring correctly you can check it at http://beta.cmela.com/shop/dizyn/

But there is problem of images and css, they are not working, what can i do for this?

thank you
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: small reguller express issue

Post by Zoxive »

itsmani1 wrote:Here is my express:

Code: Select all

 
RewriteEngine on
RewriteRule ^shop/(.*)/ index.php [nc]
what's is happening is its converting every .com/shop/anything/ to index.php

its transferring correctly you can check it at http://beta.cmela.com/shop/dizyn/

But there is problem of images and css, they are not working, what can i do for this?

thank you
That Regular Expression is working exactly how it was written.
Making the Rewrite route everything to index.php, .* matches everything.

A common way to combat this is with a check to see if the file or folder actually exist, then stop rewriting.

Code: Select all

RewriteCond %{SCRIPT_FILENAME} -f [OR] # If it is a File
RewriteCond %{SCRIPT_FILENAME} -d # Or it is a Directory
RewriteRule .* - [L] # Route to that, Last Rule
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: small reguller express issue

Post by GeertDD »

Or even:

Code: Select all

...
RewriteRule ^ - [L] # Route to that, Last Rule
You can stop matching right at the beginning.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Re: small reguller express issue

Post by itsmani1 »

I tired following code but no luck

Please see: http://beta.cmela.com/shop/dizyn/

Code: Select all

RewriteEngine on
RewriteRule ^shop/(.*) index.php [NC]
rewritecond %{script_filename} -f
rewritecond %{script_filename} -ds
Post Reply