Hi all, I run a restaurant review site for one city, and am in the process of rewriting some of the code so that I can add new cities easily with no new code
neccesary each time I add one. I also really want to keep the SEO rankings I'm getting. I'm finding mod_rewrite really tricky to work out, so was hoping
someone would be so kind as to help me out?
I need a .htaccess file to do the following:
Rewrite all URLs for city and preserve any querystrings, e.g.
mydomain.com/london/index.php
mydomain.com/london/search.php?type=new
mydomain.com/london/10.php
rewritten to
mydomain.com/index.html?city=london
mydomain.com/search.html?city=london&type=new
mydomain.com/restaurant.php?city=london&rid=10
Basically all address in folder thecity written to root page.php?city=thecity, but css and image/flash links need to stay relative to the root.
Even better, would I be able to have something such as the restaurant's name instead of an ID number? Would this help with SEO rankings?
Here is my current .htaccess file that a friend wrote for me when I launched 3 years ago. The rules for the search.php page need to be kept intact but taking
into account the new city folder structure.
Code:
RewriteEngine on
RewriteBase /
RewriteRule ^brighton.html$ /search.php
RewriteRule ^viewall.html$ /search.php?orderby=name
RewriteRule ^toprated.html$ /search.php?top=true
RewriteRule ^new.html$ /search.php?new=true
RewriteRule ^mostreviewed.html$ /search.php?most=true
RewriteRule ^([A-Za-z0-9-]+).html?$ /restaurant.php?rid=$1
RewriteCond %{HTTP_HOST} !^(.*)\.mydomain\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
Am I being an idiot? Is it something really simple that I should be able to work out or am I trying to do something the wrong way? Mod_rewrite is obviously a ver powerful tool, and I would love to be able to make full use of it. I wasn't sure if it was a good idea or etiquette to add my site's address to this post but I can if it will help (edit: whoops, just realised it's in my sig any way!).
I would really really appreciate some help with this as even though PHP is not a problem for me, mod_rewrite is becoming a real pain! Every time I think I've fixed something I seem to break another thing!