简体   繁体   中英

Convert .php extention to .html for all files in particular folder using htaccess

I have folder called Pages which contains .php files. I want to convert .php extention to .html for this particular folder only.I have the .htaccess code to convert the extention

RewriteRule ^([a-z0-9_]+)\.html$ /index.php$1 [NC,L] 

But I wanted to make changes for the Particular folder only.

Any ideas???

it will change all php files to html files like foo.php to foo.html

RewriteEngine On

RewriteBase /

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

The .htaccess file relates to the folder in which it placed in and to all the other subfloders.

Therefore, if you want to apply some rewrite rules only to one folder, you need to put an htaccess in that specific folder.

You do this by specifying the folder name after the RewriteBase line in your .htaccess as shown below.

RewriteEngine On

RewriteBase /sampleFolder/

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

 

convert .php extension to .html extension in subdirectory using .htaccess file (convert .php extension to .html extension for all files in particular folder using .htaccess file)

RewriteEngine on  
RewriteBase /subdirectory name

Example

RewriteEngine on  
RewriteBase /gallery

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