1

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???

2
  • Where did you put the .htaccess file? Commented Sep 12, 2011 at 5:51
  • Why do you want to show the .html extension in the URL? Browsers don't need it. Commented Sep 12, 2011 at 9:35

4 Answers 4

3

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] 
Sign up to request clarification or add additional context in comments.

Comments

2

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.

3 Comments

I had checked now by putting the htaccess file in the particular folder, but its not working.Do i need to change anything in the code.
You sometimes need to add a "RewriteBase Pages"
I don't think that RewriteBase is needed here. @Ullas Can you post your entire htaccess file and recheck that you don't have any other htaccess files in directories which are above the desired folder?
0

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]

 

Comments

0

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] 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.