Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Sub Domain help - Please?

         

etdebruin

5:13 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



.htaccess is fun! :)

I am trying to do the following:

[city-name.state.example.com...]

rewrite to:

http://www.example.com/state/city-name/

Slowly but surely I am starting to understand the difference between $1 and %1, but how do I parse out the city-name and state from the incoming URL?

jdMorgan

5:23 pm on Aug 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



etdebruin,

Welcome to WebmasterWorld!

This search [google.com] should get you started; There are many examples posted here. Also, see the references cited in our forum charter [webmasterworld.com].

Jim

etdebruin

5:25 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



# Verify subdomain is not www
RewriteCond %{HTTP_HOST}!^www [NC]
# Extract the subdomain part
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)\.example\.com [NC]
# Do internal rewrite from subdomain/ to script with id
RewriteRule ^(.*) /%2/%1

I omit the [L] at the end because I have other rewrites further down that handle the /state/city-page URL's.