mod rewrite for subdirectory

by Lukas
2 replies
Hi,

I have a static site (design done already) and need to do the following:
for state listings

example.com/marketing/new-york.html - it lists the cities in New York that offer marketing
(bronx, brooklyn, queens, buffalo, long-island..etc)

their domain will be example.com/marketing/new-york/brooklyn.html

It will be this way for other states too,
example.com/marketing/florida.html
example.com/marketing/florida/tampa.html

so what is the proper htacess mod rewrite for this

to appear as example.com/marketing/new-york
example.com/marketing/new-york/brooklyn/


When I did it, I just got errors because of conflicting pages...a new-york state page, and then a new-york, they just did not display at all or I got big time errors so I conceded on 1 site and don't want to do the same with a new site going up.


Thanks
#mod #rewrite #subdirectory
  • Profile picture of the author webpro4hire
    Lukas,

    Not quite sure what you're trying to rewrite TO / FROM. Also, do you need rewriting at all? A static site is a static site .. no parameters, no db calls.

    We need more details to help you out.

    WP4H
    {{ DiscussionBoard.errors[3204073].message }}
  • Profile picture of the author SteveJohnson
    So you just want to use addresses without the ".html" file extension?

    No guarantees, I had no time to test this:
    Code:
    RewriteEngine on
    ## if the visitor was nice enough to add a trailing slash
    ## to the requested URL
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^([^/]+)/$ $1.html 
    
    ## if they were not that nice,
    ## force trailing slash if request is not
    ## for some other kind of file (images, etc.)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[3204570].message }}

Trending Topics