meelee
meelee

Reputation: 13

removing subfolder name and file extension from url using htaccess

I want to remove the seo/ folder name and the file extension(.html) from the below url. I am working on a static html website.

www.example.com/seo/advanced-system.html to www.example.com/advanced-system/

In .htaccess of my root folder I have written this,

RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^seo/(.*)$ www.example.com/$1 [L,R=301]

In .htaccess of my subfolder I have written this,

RewriteRule ^(.*)$ /$1 [R=301,L]

I googled and tried all possible ways, but not able to find the solution. Please help me.

Upvotes: 1

Views: 873

Answers (2)

anubhava
anubhava

Reputation: 784898

In .htaccess of my root folder, use this

RewriteEngine On

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

In .htaccess of /seo/, use this:

RewriteEngine On
RewriteBase /seo/

RewriteCond %{DOCUMENT_ROOT}/seo/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ $1.html [L]

Upvotes: 0

Ranjith Kuamr K R
Ranjith Kuamr K R

Reputation: 93

Try this

        RewriteEngine On 
        RewriteRule ^$ seo/ 
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteCond %{REQUEST_FILENAME} !-d 
        RewriteRule ^(.*)$ seo/$1

Upvotes: 0

Related Questions