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?

Link to comment
Share on other sites

# 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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.