RewriteRule to Hide Directory Name from URL

Discussion in 'Apache' started by kampbell411, Oct 31, 2011.

  1. #1
    Hi,

    I was wondering if someone could please help me with this rewrite rule below.

    I want to make the following rewrite:

    domain.com/city/FL/Miami.html

    to

    domain.com/FL/Miami.html

    I am really just trying to hide the "city" in the url. Thanks!
     
    kampbell411, Oct 31, 2011 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    Well, basically you can do something like this for that specific state/city:

    
    RewriteRule ^FL/Miami.html$ /city/FL/Miami.html [L]
    
    Code (markup):
    Or something that would cover all the cities in FL state:

    
    RewriteRule ^FL/([^/]+).html$ /city/FL/$1.html [L]
    
    Code (markup):
    So the full rewrite code would be:

    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^FL/([^/]+).html$ /city/FL/$1.html [L]
    
    Code (markup):
    Put it in your .htaccess file in your main/root html folder.
     
    pr0t0n, Nov 1, 2011 IP