For my site, I want to have all the urls rewritten from .php to .html so all the urls in the directory should be done like that automatically. Doing this just for one file is relatively easy (as shown by the code I've got below) but is there anyway just to rewrite all files with the .php extension to .html files? Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteRule ^index\.html$ index.php [T=application/x-httpd-php,L] Code (markup): If there isn't an automatic solution to do all the urls in the directory, would I just have to keep adding RewriteRule ^page-name\.html$ page-name.php [T=application/x-httpd-php,L] Code (markup): below the last line for every different page name? Thanks
Why are you changing them? why not just have the html pages parsed as php? that way you get the best of both worlds. You can add this to the htaccess. AddHandler application/x-httpd-php .php .html .htm if not then mod rewrite RewriteEngine on RewriteRule ^(.*)\.html $1\.php I think that is about it, although I am sure others more capable than I will confirm/deny/improve on the above
Ok, I'll give that a go. Basically the reason for it was I had to make the pages all php so I could gzip them (by adding the code in the header) but then all my previous pages that were linked to had the .htm extension, so I have to have them as the html pages.
Looks good and pretty easy to add to the php! BTW, I tried to leave a comment on that page, but it didn't work- no error msg, just returned me to the blog w/o posting the comment.
Yeah, it is because I have moderation set up in order to stop the spamming from various robots. It has been moderated now
or you can use mod_gzip in apache. Haven't looked at the documentation in a while, but as I remember it, it negotiates gzip compression for all pages if the browser supports it.
Yeah, that is probably the best solution, but for those on hosting where you have snobby admins, this works best. EDIT - Ahhhh, lol. I finally understand what you mean by that. The top code works perfectly and the .html pages seem to parse as php perfectly. Thanks a lot, that was much easier than the other solution.
Lest say i dont have a .htaccess file in the folder i want to make it work as php with html, how do i create a new one, and what lines should i write into it?
Hello David. You should create htaccess.txt on your pc, write the code below in it, than upload it to your ftp folder and change it's name there( for example, if you're using total commander as a ftp client, you can change the filename just like in windows) Options +FollowSymLinks RewriteEngine On RewriteRule ^([^.]+).html$ /$1.php [QSA,L] Code (markup): That's it. Regards, Adrian
<? RewriteRule ^page-name\.html $ page-name.php [T=application/x-httpd-php,L]?> where i place this code?
What are you asking here? The answer is above. But if you mean change the extension then you can do that manually on a page by page basis.
hi all this is my htaccess code Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^kusal.com [NC] RewriteRule ^(.*)$ http://www.kusal.com/$1 [L,R=301] RewriteRule ^(.*)\.html$ $1.php [L] is there any problem my nonwww to www is working but from php to html extension is not working how can i resolve it any suggestions
Try to use the following code: RewriteEngine on RewriteCond %{HTTP_HOST} ^kusal.com [NC] RewriteRule ^(.*)$ http://www.kusal.com/$1 [L,R=301] RewriteCond %{REQUEST_URI} ^(.*)\.php$ RewriteRule ^(.*) /$1.html [R=301,L] Code (markup):