jonbon
jonbon

Reputation: 1200

RewriteCond not working - Removing blog from url

I've searched through like 15 stackoverflow questions and searched/read Phile docs, and I'm not sure why I'm having an issue. I'm using Phile and I've got a /blog-folder/ where all of my posts are going to go. I'm trying to remove the /blog-folder/ from the post URLs -- right now they are example.com/blog-folder/post and I just want example.com/post.

This is my current .htaccess without caching stuff

#####################################
# Redirect stuff
#####################################
<IfModule mod_rewrite.c>
    # Enable URL rewriting
    RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301,NC]

# RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule .* index.php [L]

   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)/?$ /blog-folder/$1 [NC,L]
</IfModule>
#####################################
# disable dir
#####################################
Options -Indexes

Upvotes: 1

Views: 74

Answers (3)

Joe
Joe

Reputation: 4897

Try using this:

RewriteEngine On
RewriteRule ^blog-folder/(.*)$ /$1 [L,R=301]

Should leave you with the URL: example.com/post. Make sure you clear your cache before testing.

Upvotes: 0

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

I think you are having problem of using same condition for multiple rule.

Try it like this I am assuming everything is handled by index.php file which resides in blog-folder.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/?$ blog-folder/index.php [NC,L]

Now access it by example.com/post it will rewritten to index.php which is handling the request.

Upvotes: 1

Mr world wide
Mr world wide

Reputation: 4814

Its easier then you expected just follow this

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f [NC] 
RewriteRule ^(.*?)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME}.html -f [NC] 
RewriteRule ^(.*?)/?$ $1.html [L]

RewriteCond %{REQUEST_FILENAME}.blog-f [NC] 
RewriteRule ^(.*?)/?$ $1.blog[L]

Upvotes: 0

Related Questions