Jump to content

Apache redirect/rewrite .php extension to .html


random1

Recommended Posts

All I need my code to do is replace the .php extension to .html

 

I have the following code snippet in my .htaccess file:

 

# Redirect .php files to .html files (SEO friendly) [internal and External]
RewriteBase /
RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
RewriteRule ^(.*)\.html$ $1.php [R=301,L]

 

It redirects but it cuts out the folder name I have on the server.

 

E.g.

 

it redirects: https://localhost/website/admin.php

 

to https://localhost/admin.html NOT https://localhost/website/admin.html as it should.

 

Any ideas?

# Redirect .php files to .html files (SEO  friendly) [internal and External]
RewriteBase /
RewriteRule  ^(.*)\.php$ /$1.html [R=301,L]
RewriteRule ^(.*)\.html$ $1.php  [R=301,L]

 

You have to change your RewriteBase from / to /website

I think it would do the trick

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.