Linto
Linto

Reputation: 1282

Changing file extension using .htaccess

I'm working on Ubuntu.(Linux)

I want to display all .php pages to .html in the browser, using .htaccess. Where all php files are in the folder 'test'

e.g one.php should be one.html like and all other files too

Upvotes: 0

Views: 662

Answers (3)

Andreas
Andreas

Reputation: 5335

You mean all requests made on a X.html page to be served as X.php by the server...

If you mean this then you have to write a ReWrite Rule in the .htaccess file that Directs apache to serve any requests for X.html as requests to X.php.

You can check the following urls for details

http://www.modrewrite.com/

http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html

You can also try

RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\.html$ $1\.php [L]

Upvotes: 0

Tim
Tim

Reputation: 812

You could name the files as .html and use this in htaccess:

AddType application/x-httpd-php .html

Or to keep the files as .php and just redirect .html to the PHP files use this:

RewriteEngine on 
RewriteRule ^(.*)\.html $1\.php

Upvotes: 0

markcial
markcial

Reputation: 9333

I'm not very sure about what you are trying to do, but i guess that you are trying to redirect /test/foo.html to /test/foo.php you could try it with

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^(.+).html$ $1.php [QSA]
</IfModule>

hope it helps

Upvotes: 3

Related Questions