How to mod_rewrite "ONE file" from .php to .html in .htaccess? - .htaccess

What is the syntax to mod_rewrite "ONE file" from .php to .html in .htaccess? I have syntax for ALL files, but how do I do that for one file?
Thanks

In htaccess in the document root :
RewriteEngine on
RewriteRule ^file.php$ /file.html [L]
This will internally map /file.php to /file.html

Related

Hiding subfolders from URL through .htaccess

How do I hide all subfolders from the URLs on my site?
So http://www.example.com/whatever just shows as http://www.example.com.
Just put this into you htaccess:
RewriteEngine On
RewriteRule ^ index.php [L]
All your request will be rewritten to index.php, which will achieves what you're describing.

How to 301 redirect when have two .htaccess files

I am trying to enable a 301 redirect on my site cornwallcats.co.uk
I seem to have two .htaccess files in my root directory. One shows following and appears as a .txt file:
AddHandler x-mapp-php6 .html .htm
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www.cornwallcats.co.uk [NC]
RewriteRule ^(.*)$ http://cornwallcats.co.uk [L,R=301]
The other only shows (and has no filetype?):
AddHandler x-mapp-php6 .html .htm
Any help as to which .htaccess file I should edit would be really helpful!
Thanks
Transfer the contents of .htaccess.txt to .htaccess and then delete the file named .htaccess.txt.
If you want to add 301 redirect directives to your .htaccess file, you need to add them after
RewriteEngine On

Htaccess redirection 301 folder

I'd like to do a redirect with htaccess file of my old links
www.domain.com/220262/page.html to www.domain.com/video/220262/page.html
thank you
This should work:
RewriteEngine On
RewriteRule ^([0-9]+)/page.html /video/$1/page.html [R=301,L]

redirect all .html extensions to .php

I want to update all the pages on a website to use include for the footer and header. So I have to change a lot of .html pages to .php.
So i'm looking for a way to redirect all pages that end with .html to the same url but ending in .php.
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
If you want it to be done as a redirect instead of just a rewrite modify the [L] to [L,R]
You could do a more simple approach and have all your html files be processed as php files by adding the following line to your .htaccess
AddHandler application/x-httpd-php .php .html
mod_rewrite to the rescue!
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php
In your apache httpd.conf file you can add
AddType application/x-httpd-php .html
to make .html files go through the php parser before they are served to the user. You can also add this directive to your .htaccess file. The second method may not work depending on how your host is setup.
If you want an actual HTTP 301 Moved Permanently Redirect
RewriteEngine on
RedirectMatch 301 ^(.*)\.html$ $1.php
or
RewriteEngine on
RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1.html [L,R=301]
Note that the AddType command will process your existing html file as php. If what you wanted was to replace an existing html file with a new php file you need to use the rewrite rule.
The rule need needs a / in front of $1 otherwise, at least in my cPanel, the file I'm redirected to has the full path, including the home folder etc
RewriteEngine On
RewriteRule ^(.*).html$ /$1.php [L,R]

Htaccess redirect

Does anyone have a simple way of rdirected in .htaccess all pages that were once .asp to now be .php. For example index.asp is now index.php etc. Server is apache.
RewriteEngine on
RewriteRule ^(.+)\.asp$ $1.php

Resources