Reputation: 59
My folder structure looks like this:
domain.com/html/page.html
.
If I click on a link on the page I want the URL to look like this: domain.com/page
.
I tried out different .htaccess snippets but nothing worked the way I want. At the moment you can visit domain.com/html/page
and you see the right page, but if you click on a link the URL is domain.com/html/page.html
.
My .htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /$1.html [QSA,L]
I hope, someone can help me, thanks in advance!
Upvotes: 1
Views: 70
Reputation: 19016
You can put this code in your htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /html/some-page.html to /some-page
RewriteCond %{THE_REQUEST} \s/html/([^/]+)\.html\s [NC]
RewriteRule ^ %1 [R=301,L]
# Rewrite /some-page to /html/some-page.html if it exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/html/$1\.html -f
RewriteRule ^([^/]+)$ html/$1.html [L]
Upvotes: 3