Portal Home > Knowledgebase > Articles Database > how to mod_rewrite


how to mod_rewrite




Posted by latheesan, 07-23-2009, 11:29 PM
hello, i am working on a website that requires search engine friendly urls. the urls are currently like this (for example): I used this tool (http://www.generateit.net/mod-rewrite/) to generate the following mod_rewrite rule: So, the rewritten url would look like this (for example): I run into problem, when i pass only one param into the query string, e.g. www.domain.com/?Page=Browse (where as before i was passing two). When i pass one param, the rewritten url looks odd, e.g. www.domain.com/Browse-.html (notice the dash at the end) Is there a way to do this properly? For example: domain.com/?Page=Login&Type=Customer ==> domain.com/Login-Customer.html domain.com/?Page=Browse ==> domain.com/Browse.html etc... Thanks for any help, i'm new to this.

Posted by HostSentry, 07-24-2009, 03:27 AM
If your sites only go one or two levels, just add RewriteRule ^([^-]*).html$ /?Page=$1 [L] ... below the other one. Edit: After re-reading what you wrote, I don't see how it could do what you are describing. Last edited by HostSentry; 07-24-2009 at 03:42 AM.

Posted by Dark Light, 07-25-2009, 02:40 PM
Yes, mod_rewrite can do what you are describing. You would need to use two rules within the .htaccess file; the first rule should (IMO) be the rule you already have, and then a second rule for the one part URL (e.g. /Browse.html --> ?Page=Browse where Browse is the variable, not containing the - symbol.)

Posted by MontaSEO, 07-25-2009, 08:45 PM
The url is not re-written when you request http://example.com/?Page=Browse Its the friendly URL which works as a alias for the old url. You should actually make sure that the content isn't accesible on the old URL, this can be done by throwing out a 404 if your index.php (or whatever) is requested.

Posted by latheesan, 07-26-2009, 03:16 PM
thanks guys, i think i got it. i only have 2 levels, so i tried this and it's working fine: So, im i correct to assume that a .htaccess can have multiple rewrite rules?

Posted by Dark Light, 07-26-2009, 03:30 PM
Yup, you are correct.



Was this answer helpful?

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

Also Read
jodohost.com?? (Views: 634)
VestaCP is Secure? (Views: 739)
grid environment (Views: 673)