Forum Moderators: phranque
I've also found this code:
RewriteEngine on
RewriteMap upper2lower int:tolower
RewriteRule ^/(.*)$ /${upper2lower:$1}
Would this work? Doesn't for me.
The problem with you first code snippet is that "City/" does not start with any of "A/" "B/" "C/" or <anything>/ -- The pattern is simply incorrect. Fixing that and other syntax problems yields:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^a(.+)$ http://www.example.com/A$1 [R=301,L]
RewriteRule ^b(.+)$ http://www.example.com/B$1 [R=301,L]
RewriteRule ^c(.+)$ http://www.example.com/C$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^a([^/]+/.*)$ http://www.example.com/A$1 [R=301,L]
RewriteRule ^b([^/]+/.*)$ http://www.example.com/B$1 [R=301,L]
RewriteRule ^c([^/]+/.*)$ http://www.example.com/C$1 [R=301,L]
I only want my cities directories to be modified, to be able to point domain.com/phoenix to domain.com/Phoenix when someone types in he lowercase version, or some reason gets linked with the lowercase version...
Would it be better to write a line for each city individually? I do have all my cities in the state folder state/city but have written the url to show domain.com/city.
If you are using a rewrite, you will eventually get multiple URLs indexed for the same content. That Duplicate Content will cause you problems.
So far you have used a redirect in your code. That is good.
If there are a small number of URLs that do not need to be modified, add a RewriteCondition that excludes them. Not is done with a ! in front.
The key is that you must provide some way to differentiate between URLs that need to be redirected, and those that don't; mod_rewrite by itself doesn't know a city from a Citroen.
Jim
Options +FollowSymLinks
RewriteEngine on
#
# If file exists as requested, skip uppercasing (next 28 rules)
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^[a-z].+$ [S=28]
#
# Else uppercase first letter of URL-path
RewriteRule ^a([^/]+/.*)$ http://www.example.com/A$1 [R=301,L]
RewriteRule ^b([^/]+/.*)$ http://www.example.com/B$1 [R=301,L]
RewriteRule ^c([^/]+/.*)$ http://www.example.com/C$1 [R=301,L]
Jim
http://www.example.com/florida
redirects you to:
http://www.example.com/Florida/
They have that with every state. Whats the best way I can get to that, still keeping my current setup of domain.com/city with the pages in state/city. Can't be done?
[edited by: jdMorgan at 3:01 am (utc) on Sep. 21, 2007]
[edit reason] example.com [/edit]
Options +FollowSymLinks
RewriteEngine on
#
# If file exists as requested, skip uppercasing (next 28 rules)
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/State/[a-z].+$ [S=28]
#
# Else uppercase first letter of URL-path
RewriteRule ^State/p([^/]+/.*)$ http://www.example.com/P$1 [R=301,L]
Works, is there a problem doing it this way?
domain.com/city to example.com/City even dough my real structure is example.com/state/city
[edited by: jdMorgan at 3:02 am (utc) on Sep. 21, 2007]
[edit reason] example.com [/edit]
Options +FollowSymLinks
RewriteEngine on
#
# If file or directory exists as requested, skip uppercasing (next 28 rules)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule [b]^Sta[/b]te/[a-z].+$ [S=28]
#
# Else uppercase first letter of URL-path
RewriteRule ^State/a([^/]+/.*)$ http://www.example.com/A$1 [R=301,L]
...
RewriteRule ^State/z([^/]+/.*)$ http://www.example.com/Z$1 [R=301,L]
[edited by: jdMorgan at 3:00 am (utc) on Sep. 21, 2007]
How about http://www.domain.com/city/Las.Vegas and http://www.domain.com/state/Florida type URLs. The "marker" makes it easy to process.
Make sure that you avoid spaces and underscores in multi-word names. Use a hyphen or dot between words.