I am trying to make a new website of mine more search engine friendly but are not getting the htaccess rules to work for mod_rewrite. The server has been enabled for mod_rewrite and I got some commercial scripts on other sites that work fine with htaccess / mod_rewrite. Sample URLs I want to convert are: http://www.mydomain.com/category.php?type=18 http://www.mydomain.com/category.php?type=18&sec=42 http://www.mydomain.com/viewlisting.php?view=6 I tried this RewriteEngine On RewriteRule ^categories/(.*).php /category.php?type=18 but that does not anything and I am kinda lost. Any helpful hint would be appreciated. Thanks. Chris
Hello Nsusa, First of all, hello everybody! This is my first post here! A correct mod_rewrite approach for URLs like: http://www.mydomain.com/category.php?type=18 http://www.mydomain.com/category.php?type=18 Are the following two .htaccess lines: RewriteEngine On RewriteRule ^categories/(.*).php /category.php?type=$1 You may want to try also: RewriteEngine On RewriteRule ^categories/(.*)/(.*).php /category.php?type=$1&sec=$2 That's for having http://www.mydomain.com/categories/18/42.php instead of http://www.mydomain.com/category.php?type=18&sec=42. It is also possible to have .htaccess disabled (from a AllowOverride rule) or mod_rewrite might not be loaded (you can check by analyzing the output oh phpinfo()). Good luck!
Ah, I've been beat to it while I was writing my reply ... I was replying the same, but with a couple suggestions. I'd change the asterisk (*) to a plus (+), because asterisk means "match zero or more times", but a valid filename must have at least 1 character (plus means "match one or more times"). I'd also change the period, because periods mean "match ANY character", which may or may not be a security hazard. I believe ([:alnum:\-\_]+) allows for all letters, numbers, and the minus (-) and underscore (_).
Actually - it seems like maker of the script has put something into the code that causes the problem of "not working" $id = $rs['id']; if($modrewrite=="Y"){ $link="category/".$id; }else{ $link="category.php?type=".$id; } PHP: He is selling his own SEO hack for the script. Chris
If you're going to do mod_rewrite, make the URLs static, ie with no sign of .php. Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^categories/(.*)/sec/(.*)/$ category.php?type=$1&sec=$2 [L] RewriteRule ^categories/(.*)/$ category.php?type=$1 [L] RewriteRule ^view/(.*)/$ viewlisting.php?view=$1 [L] domain.com/categories/WHATEVER/sec/WHATEVER/ domain.com/categories/WHATEVER/ domain.com/view/WHATEVER/
indeed! might even want to make them .html's and make changes so .html files are parsed by php. i'm debating about bothering with that extra part right now myself, for the added filename keyword and my theory that google treats /dir/file.html more importantly than just /dir/
All this talk about "categories" and "sec" ... I didn't even realize your making URLs more difficult than they need. Instead of RewriteRule ^categories/(.*)/sec/(.*)/$ category.php?type=$1&sec=$2 [L] make it RewriteRule ^(.*)/(.*)/$ category.php?type=$1&sec=$2 [L] so that instead of converting domain.com/categories/22/sec/12 you get domain.com/22/12
He had 'categories/' in his example, so I kept them there. ::RewriteRule ^(.*)/(.*)/$ category.php?type=$1&sec=$2 [L] The last thing you want to do is mess up the whole site. With that example, if other parts of the site had a directory and sub directory, atleast the index page would be messed up, unless maybe if you also had index.xxxx in the link. Having one word in the first part fixes that.