Home How to redirect .php to .html using .htaccess
Reply: 2

How to redirect .php to .html using .htaccess

Manvendra Rajpurohit
1#
Manvendra Rajpurohit Published in 2018-01-12 06:34:55Z

This question already has an answer here:

  • 301 Redirect *.php to *.html via .htaccess? 1 answer

I uploaded my code on testing server and link is below

http://dynamicwebsite.co.in/kk/ksmotors/tafe/aboutus.html

Now I want when someone hit below URL then user redirect to above URL

http://dynamicwebsite.co.in/kk/ksmotors/tafe/index.php?page=aboutus.php

I used following .htaccess code but its not working

RewriteEngine On

#RewriteRule ^index.php?page=(.*).php/?$ $1/$2.html$3 [R=301,L]
#RedirectMatch 301 /form/5/.* www.example.com/form/12/name.html

RedirectMatch 301 /index.php?page=aboutus.php http://dynamicwebsite.co.in/kk/ksmotors/tafe/aboutus.html

#Disable php and html files in storage folders
RedirectMatch 403 (admin\/accessory\/images|admin\/careers\/images|admin\/categories\/images|admin\/css|admin\/images|admin\/jqgrid|admin\/models\/images|admin\/submodels\/images|css|images|js|php-captcha|resume|spec_doc).+\.(php|php3?|phtml|html)$

#Disable Directory Listing
Options -Indexes

can you please explain what is going wrong. Please help. Thanks

Nims Patel
2#
Nims Patel Reply to 2018-01-12 06:42:42Z

Add below code in .htaccess file

RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

Rewriting a URL

This example rewrites a URL to another URL. This rewrites example.com/1.html to example.com/abc.php?id=1

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]

Refer link

Pravin Prajapati
3#
Pravin Prajapati Reply to 2018-01-12 07:46:05Z

you can add this in your .htaccsess file if you want to redirect to html from php. add your pagename in code.

RewriteEngine on 
RewriteBase / RewriteCond %{THE_REQUEST} \ /(.+)\.php 
RewriteRule ^ /%1.html [L,R=301] 
RewriteRule ^pagename\.html$ pagename.php [T=application/x-httpd-php,L] 
RewriteEngine on 
rewritecond %{http_host} ^xyz.org [nc] 
rewriterule ^(.*)$ http://xyz./$1 [r=301,nc] 
RewriteRule ^index\.html$ / [NC,R,L] 
ErrorDocument 404 /404.html

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.470138 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO