Portal Home > Knowledgebase > Articles Database > apache rewrite help


apache rewrite help




Posted by guruproj, 02-07-2011, 11:25 AM
I need a simple string replacement but couldn't make it work: I want ~~domain.com/string1/string2/id/RANDOMSTRING/ to look like ~~domain.com/request/RANDOMSTRING/ so basically "string1/string2/id" = "request" rewrite base is / please help! thanks a lot!

Posted by guruproj, 02-08-2011, 12:43 AM
Ok I found the reason it was not working: apache always add path info postfix so when it's supposed to be ~~domain.com/string1/string2/id/RANDOMSTRING/, it became ~~domain.com/string1/string2/id/RANDOMSTRING//RANDOMSTRING/ Any idea?

Posted by Natcoweb, 02-08-2011, 11:28 AM
RewriteRule ^string1/string2/id/RANDOMSTRING /request/RANDOMSTRING$1 [L,QSA]

Posted by guruproj, 02-08-2011, 06:10 PM
thank you, but it doesn't work. domain.com/request/RANDOMSTRING/ is what I'll be using in browser and domain.com/string1/string2/id/RANDOMSTRING/ is where the url actual is. Also, "RANDOMSTRING" changes without pattern. So I need to replace /string1/string2/id/ with /request/ but need to keep "RANDOMSTRING" as it is. I currently have RewriteRule ^/request/(.*)/$ /string1/string2/id/$1/ but in rewrite log, I saw apache added one more "RANDOMSTRING", so it tries to point at /string1/string2/id/RANDOMSTRING//RANDOMSTRING/

Posted by Natcoweb, 02-09-2011, 01:34 PM
RewriteRule ^request/(.*)/$ /string1/string2/id/$1/ [L,QSA] should work. You don't have to add anything at the end of the line. What's your version of apache?



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
SkyBerate Outage (Views: 694)

Language: