2

i have problem with my site, when i try to convert php to html, i got this error Not Found

and this is .htaccess

RewriteEngine on
RewriteRule ^(.*)\.php$ /ver1/$1.html [R=301,QSA,L]

all files in folder ver1

i see this post

.php url to .html url

but not work with me

i just need convert php to html and if i go to index.php

i go to index.html and make all url html

Community
  • 1
  • 1
C0der Man
  • 21
  • 1
  • 5

5 Answers5

4

Rename your .php file to .html and add this line in your .htaccess

AddType application/x-httpd-php .html .htm
ASR
  • 1,801
  • 5
  • 25
  • 33
  • 2
    Wow really? "Just rename every file in your site and re-factor your code to fix all the includes... it's easy" You have to be kidding... – msEmmaMays Sep 06 '12 at 04:17
  • This code will parse HTML files as PHP - http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/ – ASR Sep 06 '12 at 04:26
  • Apologies for 'all your .php files' - rename only the files which you need to parse.. – ASR Sep 06 '12 at 04:28
  • Sure this is the right way - but if he only had one or two files he would have done that already - the fact that he is looking for a solution this complicated would tend to imply he has alot of .php files he would have to rename . Also he still needs to refactor his code to fix any links or forms if he does what you suggest - which could involved some major code updating – msEmmaMays Sep 06 '12 at 04:35
0

You need to add /ver1/ in both places - "^(.).php$" -> "^/ver1/(.).php$"

But that line just turns off the .php version - you never copied the line that tells it to actually serve the PHP files under the different extension (RewriteRule ^(.*).html$ $1.php)

RewriteEngine on 
RewriteRule ^/ver1/(.*)\.html$ /ver1/$1.php
RewriteRule ^/ver1/(.*).php$ /ver1/$1.html [R=301,QSA,L]

The first rule will internally map .html to .php files and serve them directly to the client

The second rule will REDIRECT anything .php under /ver1/ to it's .html equivalent for SEO purposes

Edit - Warning - if you have any HTML forms that are action=POST data - you MUST update their action to point to the .html version - otherwise they will stop working (POST data is not redirected!)

msEmmaMays
  • 1,073
  • 7
  • 7
  • i use RewriteEngine on RewriteRule ^/ver1/(.*)\.html$ /ver1/$1.php RewriteRule ^/ver1/(.*).php$ /ver1/$1.html [R=301,QSA,L] url not convert and move to html – C0der Man Sep 06 '12 at 04:41
0

Are you looking for "How do I rewrite .php to .html using .htaccess rules"????????????????

If yes, use

RewriteEngine on
RewriteRule ^(.*)\.html$ /ver1/$1.php [nc]
Shail
  • 1,565
  • 11
  • 24
  • Still wrong - all his code is in /ver1/ folder so you are telling it do this - "/ver1/file.html" -> "/ver1/ver1/file.php" – msEmmaMays Sep 06 '12 at 04:33
  • i not need change ext for all files and samo files pure php and i test this RewriteEngine on RewriteRule ^(.*)\.html$ /ver1/$1.php [nc] but url not change like vb.php not direct vb.html – C0der Man Sep 06 '12 at 04:40
0

Try it on .htaccess:

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)\.html$ /$1.php
OpenWebWar
  • 580
  • 8
  • 16
-1
RewriteRule ^(.*)\.html$ $1.php [nc]
Keyur Shah
  • 11,043
  • 4
  • 29
  • 48