tags:

views:

250

answers:

3

i am using IIRF v2.1 for Rewrite Rule

i write on rule like this but its not working

RewriteRule ^(prod|pag|staf)/([A-Za-z0-9-]+)/?$ $1.php?iid=$2 [QSA,L]

if i use follwoing url

http://localhost/prod/22/new-item

what i need actual URL is http://localhost/prod.php?iid=22

yes working version is

RewriteRule /^(prod|pag|staf)/([A-Za-z0-9-]+)/?$ /$1.php?iid=$2 [QSA,L] but problem here is all the style and include files are not included.

Thanks

A: 

If you're URLs will always contain the numbers then the slug, this regex will get each part:

^(prod|pag|staf)/([0-9]+)/([A-Za-z0-9-]+)/?
John Sheehan
+1  A: 

Your regex doesn't allow for new-item to follow the final slash.

RewriteRule ^(prod|pag|staf)/([A-Za-z0-9-]+)/?$ $1.php?iid=$2 [QSA,L]

The /?$ sequence that ends the pattern says... a slash (maybe) and then the end of the string. Your URL, however, does not end in a slash. It ends with a slash and the text "new-item".

A regex that captures that would be something like this:

RewriteRule ^(prod|pag|staf)/([A-Za-z0-9-]+)/? $1.php?iid=$2 [QSA,L]

...which says, you don't care what comes after the optional slash, and because you are using QSA, then any query string in the original URL is appended to the outgoing URL.

But that would basically discard the "new-item" portion of the incoming URL request, which I am not sure you want to do.

Cheeso
+1  A: 

just write url like this

RewriteRule ^/(prod|pag|staf)/([A-Za-z0-9-]+)/?$ /$1.php?iid=$2 [QSA,L]

and put / before your style sheets and other includes

like

if your old style sheet is include like this

   style/style.css

chnage it to

  /style/style.css

same for image and links. hope this will work fine.