How to execute php files with .html extension? - php

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

Rename your .php file to .html and add this line in your .htaccess
AddType application/x-httpd-php .html .htm

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!)

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]

Try it on .htaccess:
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)\.html$ /$1.php

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

Related

Rewrite html file for php with .htaccess

I need help with converting html with php .
So far My code is
RewriteEngine on
RewriteRule ([a-z]+).html /$1.php
This is working fine. but some real html pages have php scripts ,that doesnt run. how to fix this? thanks
You can use AddHandler
directive to change the mime type
of a file
Add the following line to your htaccess file
AddHandler application/x-httpd-php .html
Now all your html files will work as php.
Try this:
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

Rewrite .php to display .htm

I want to show a .php file as a .htm extension. This is what I thought would work, but it doesn't:
RewriteEngine On
RewriteBase /
RewriteRule ^contact\.php$ contact.htm [NC,R,L]
Any help would be greatly appreciated. Thank you.
Add this to your .htaccess file to allow PHP in HTML files:
# allow HTML files to process PHP
AddType application/x-httpd-php .html .htm
# now the rewrite can occur
RewriteEngine On
RewriteBase /
RewriteRule ^contact\.htm$ contact.php [NC,R,L]
With that in there you can rewrite the URL.
You are very close. You have got the rewrite rule parameters reversed - the first parameter is what you are listening for (content.html) and the second is what you want to load instead (contact.php). I have also removed the R flag so the server does this internally - with the R flag the server will send a command to the browser to force it redirect to the new location.
RewriteEngine On
RewriteBase /
RewriteRule ^contact\.htm$ contact.php [NC,L]

Redirect file extension (.htaccess)

I was wondering if it were possible to redirect certain ending file types to another extension. It's been done before on a site I visited, but I am unable to find out how.
For exmaple:
If my website had php files and the extension was www.example.com/testfile.php and I want it to show up on the URL as www.example.com/testfile.aspx, how would I do that?
Thanks
You could do something like this:
RewriteEngine On
RewriteRule ^(.*)\.aspx$ $1.php [L]
or if you would prefer to actually save the files as aspx on the server instead of redirecting to a PHP script, do something like:
AddHandler application/x-httpd-php .php .aspx
Use this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]*)\.aspx$ $1.php [L]
</IfModule>

How to hide .php extension in .htaccess [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Remove .php extension with .htaccess
I'm trying to hide the .php file extension but for some reason can't get it to work. My latest attempt was the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^folder/([a-zA-Z_\-0-9]+)/?$ /folder/$1.php
</IfModule>
I have tried many different variances of code I have found online but still no luck. The .htaccess file is placed within the root directory.
I've used this:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless URL
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]
# Resolve .php file for extensionless PHP URLs
RewriteRule ^([^/.]+)$ $1.php [L]
See also: this question
The other option for using PHP scripts sans extension is
Options +MultiViews
Or even just following in the directories .htaccess:
DefaultType application/x-httpd-php
The latter allows having all filenames without extension script being treated as PHP scripts. While MultiViews makes the webserver look for alternatives, when just the basename is provided (there's a performance hit with that however).
1) Are you sure mod_rewrite module is enabled? Check phpinfo()
2) Your above rule assumes the URL starts with "folder". Is this correct? Did you acutally want to have folder in the URL? This would match a URL like:
/folder/thing -> /folder/thing.php
If you actually want
/thing -> /folder/thing.php
You need to drop the folder from the match expression.
I usually use this to route request to page without php (but yours should work which leads me to think that mod_rewrite may not be enabled):
RewriteRule ^([^/\.]+)/?$ $1.php [L,QSA]
3) Assuming you are declaring your rules in an .htaccess file, does your installation allow for setting Options (AllowOverride) overrides in .htaccess files? Some shared hosts do not.
When the server finds an .htaccess file (as specified by
AccessFileName) it needs to know which directives declared in that
file can override earlier access information.

Rewrite .php to .aff and treat .aff as php

On my website I have an affiliates/ folder.
Inside that I have showgames.php
I want to be able to access the file as www.website.com/affiliates/showgames.aff
Inside affiliates folder,I placed this .htaccess
AddType application/x-httpd-php .php .aff
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.php$ $1.aff [R=permanent]
For some reasons , it doesnt work .
You misunderstand what rewriting is.
You say you have a /affiliates/showgames.php page that you want to be accessible as /affiliates/showgames.aff. This means the second must be internally rewritten to the first when it's requested, not the other way around.
This also means that you do not need to interpret .aff files as PHP scripts. Just do this in affiliates' .htaccess:
RewriteRule ^(.*)\.aff$ $1.php [QSA]

Categories