Forum Moderators: phranque
Look like this:
mydomain.com/California/San-Diego-County.html
Here's what I have in my htaccess file:
RewriteEngine on
RewriteRule ^([^/]*)\.html$ /county.php?id=$1 [L]
RewriteRule ^id/([^/]*)/id2/([^/]*)\.html$ /city.php?id=$1&id2=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /company.php?id=$1&id2=$2&id3=$3 [L]
Doesn't seem to work. Can anyone see any obvious errors?
Thanks
But mod_rewrite does not "change" URLs; It merely says, "When a client requests '/California/San-Diego-County.html', pass the request to the content.php script, and pass the 'id' to it so that it can generate the proper HTML page."
You will need to change the links on all of your pages to reference the "/California/San-Diego-County.html"-style URLs in order to "change" those URLs.
If your question really has to do with rewriting rather than changing URLs, then I'd suggest a review of the regular-expressions tutorial cited in our forum charter; The patterns in your rules are just "not quite right-looking" but because you gave only one example URL-path and no description of how you want it to work, it's impossible to know what to recommend. For example, I think I'd recommend changing your first rule to
RewriteRule ^[^/]+/([^.]+)\.html$ /county.php?id=$1 [L]
Also, I might as well warn you that you'll probably be happier in the long run if you do not mix upper- and lower-case letters in your URLs, as it is very difficult to fix mixed-case problems in .htaccess; By mixing case, you are almost guaranteed to have other Webmasters, bloggers, and forum posters making mistakes in linking to your pages. Apache, unlike IIS, is case-sensitive.
This is good because it prevents the massive duplicate-content problems (and possible search ranking penalties) inherent in a case-insensitive server, but it means that any request with a case error will go 404-Not Found on an Apache server unless you handle it and "fix-up" the requested URL. When doing so, it is far easier to force either all-lowercase, or all-uppercase. Mixed-casing is a nightmare, and pretty much has to be handled one URL at a time. That can quickly make your .htaccess file huge, and therefore, make your server very slow.
Jim
So if I type this in my browser "mydomain.com/California/San-Diego-County.html" it should display the same thing as "mydomain.com/city.php?id=California&id2=San-Diego-County"? It gives me a 404.
All I want to do is create a cleaner URL. This is for a PPC test, not worried about organic rankings for this site. Ultimately, it probably doesn't matter for the test.
I'm fairly new to this side of things, trying to learn and expand my knowledge.
RewriteRule ^([^/]+)/([^./]+)\.html$ /city.php?id=$1&id2=$2 [L]
RewriteRule ^([^./]+)\.html$ /county.php?id=$1 [L]
RewriteRule ^([^/]+)/([^./]+)\.html$ /city.php?id=$1&id2=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ /company.php?id=$1&id2=$2&id3=$3 [L]