简体   繁体   中英

Replace .php with .html for all urls in files directory

How can I Replace .php with .html ?

I have all files with .php extension in my files directory

/files
  foo.php
  bar.php

I want browser to show them as

  http://example.com/files/foo.html
  http://example.com/files/bar.html 

Is this possible by .htaccss?

Add this to your files/.htaccess

 RewriteEngine on 
 RewriteBase /files/ 
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)\.html$ /files/$1.php [NC,L]

this rewriteRule will redirect all .html requests to .php meaning that if you enter www.example.com/files/foo.html then it will be internally redirected to www.example.com/files/foo.php and your browser will remain at www.example.com/files/foo.html

You need to use URL Rewrite on your .htaccess file, there is a post with the same question and is solved already here :

Rewrite

Try this

RewriteEngine on  
RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L]  

RewriteCond %{THE_REQUEST} (.*)\.html  
RewriteRule ^(.*)\.html $1.php [L] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM