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

5
  • 2
    What do you mean by "convert php to html" ? Commented Sep 6, 2012 at 4:03
  • 1
    You're doing this backwards. If you want people to be able to access "index.html" and have it execute "index.php", you need to rewrite ".html" to ".php". Commented Sep 6, 2012 at 4:13
  • Is the .htaccess file being read? Do you have AllowSymLinks set? Commented Sep 6, 2012 at 4:14
  • possible duplicate of Change .php URL with id into .html and a million other rewrite questions Commented Sep 6, 2012 at 4:19
  • just change links and rewrite url Commented Sep 6, 2012 at 4:52

5 Answers 5

4

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

AddType application/x-httpd-php .html .htm
Sign up to request clarification or add additional context in comments.

4 Comments

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...
This code will parse HTML files as PHP - velvetblues.com/web-development-blog/…
Apologies for 'all your .php files' - rename only the files which you need to parse..
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
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!)

1 Comment

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

2 Comments

Still wrong - all his code is in /ver1/ folder so you are telling it do this - "/ver1/file.html" -> "/ver1/ver1/file.php"
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
0

Try it on .htaccess:

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)\.html$ /$1.php

Comments

-1
RewriteRule ^(.*)\.html$ $1.php [nc]

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.