Search code examples
apachewordpressmod-rewriteurl-rewritingisapi

isapi rewrite rules remove blog from wordpress url


while i am new to rewrite I will try to outline this problem in english first than start a thread on how to fix this issue with all your help.

I am trying to remove the folder /blog/ from the following url:

http://blog.site.com/blog/2011/05/26/article-name-test/

with:

http://blog.site.com/2011/05/26/article-name-test/


Solution

  • Put this code in your .htaccess file:

    Options +FollowSymlinks -MultiViews
    RewriteEngine on
    
    RewriteRule ^blog/?(.*)$ /$1 [R=301,L,NE,NC]
    

    Update: Based on your comments

    Here is your suggested .htaccess:

    RewriteCond %{HTTP_HOST} ^www\.site\.me$ [NC]
    RewriteRule ^ http://site.me%{REQUEST_URI} [R=301,L] 
    
    RewriteCond %{HTTP_HOST} ^holisticho\.me$ [NC]
    RewriteRule ^blog/ http://blog.site.me [R=301,L,NC]
    

    Chris Hough Current Edits

    Options +FollowSymlinks -MultiViews -Indexes
    # ------------------------------------------------------------
    # Core rewrite rules
    # -----------------------------------------------------------
    RewriteEngine on
    # -----------------------------------------------------------
    # Redirect deleting leading www to root domain if no specified sub is used:
    # Allowed Subs: our, test, test.blog, local, local.blog
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} !^(our|test|test\.blog|local|local\.blog)\.holisticho\.me$ [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.holisticho\.me$
    RewriteRule ^(.*)$ http://holisticho.me/$1 [R=301,L]4
    # -----------------------------------------------------------
    # Temporary Base Redirect Until Phase One Has been completed
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} ^holisticho\.me$ [NC]
    RewriteRule ^(.*)$ http://our.holisticho.me/$1 [R=301,L]
    # -----------------------------------------------------------
    # Redirect Any Domains not speficied using /blog/ to the primary url for the blog
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} ^(test|local)\.holisticho\.me$ [NC]
    RewriteCond %{REQUEST_URI} ^/blog/$ [NC] 
    RewriteRule (.*) http://our.holisticho.me/ [R=301,L]
    # -----------------------------------------------------------
    # User can use /login or /admin to log into WP
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
    RewriteRule ^(login|admin)$ http://%{HTTP_HOST}/blog/wp-login.php [NC,L]
    # -----------------------------------------------------------
    # If the wp-admin redirect is triggered redirect to the log in page with no query string
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
    RewriteCond %{REQUEST_URI} wp-login [NC]
    RewriteCond %{QUERY_STRING} redirect_to [NC]
    RewriteRule () http://%{HTTP_HOST}/blog/wp-login.php$1?  [R=permanent,NC,L]
    # -----------------------------------------------------------
    # Add hidden "/blog/" to the url structure 
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
    RewriteRule !^blog/ blog%{REQUEST_URI} [L,NE,NC]
    # -----------------------------------------------------------
    # Wordpress Permalink formatting
    # -----------------------------------------------------------
    RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
    RewriteRule ^index\.php$ - [L,NE,NC]
    RewriteCond %{HTTP_HOST} ^(our|test\.blog|local\.blog)\.holisticho\.me$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L,NE,NC]
    # -----------------------------------------------------------
    # Site Wide Error Controllers
    # -----------------------------------------------------------
    ErrorDocument 400 /400.php
    ErrorDocument 401 /401.php
    ErrorDocument 402 /402.php
    ErrorDocument 403 /403.php
    ErrorDocument 404 /404.php
    # -----------------------------------------------------------
    # Using browser cache: FileETag MTime Size
    # -----------------------------------------------------------
    <ifmodule mod_expires.c>
     <filesmatch "\.(jpg|gif|png|css|js)$">
      ExpiresActive on
      ExpiresDefault "access plus 1 year"
     </filesmatch>
    </ifmodule>
    # -----------------------------------------------------------
    # Compress static data
    # -----------------------------------------------------------
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    BrowserMatch bMSIE !no-gzip !gzip-only-text/html
    # -----------------------------------------------------------
    # Protect blog from hotlinking
    # -----------------------------------------------------------
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?holisticho\.me/ [NC]
    RewriteCond %{HTTP_REFERER} !^$
    #Replace /images/nohotlink.jpg with your "don't hotlink" image url
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /includes/images/administrative/NoHotlinking.png [L]
    # -----------------------------------------------------------
    # Fix for infinite loops
    # -----------------------------------------------------------
    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule .* - [L]
    # -----------------------------------------------------------