0

I have a website with html pages, and a single .php page. I am trying to figure out a way to hide the .php extension from address bar.

I would like the page to be displayed as example.com/submit, and not example.com/submit.php

Also, with the .htaccess file below, I can't seem to get a google site link to redirect from the .html version of the page to the .php page.

Here is what I have in my .htaccess file:

ErrorDocument 404 /page-not-found.html

ErrorDocument 403 /access-denied.html

SetEnv TZ America/Chicago

IndexIgnore *

Options +MultiViews

RewriteCond %{REQUEST_FILENAME} (.*)\.html [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %1\.php -f [NC]
RewriteRule ^(.*).html$ $1.php [NC]

I hope someone can help me get this working.

Thanks.

It appears this answer from another thread specific to godaddy works. Not even the accepted answer, but an additional comment.

Using .htaccess to make all .html pages to run as .php files?

Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
Community
  • 1
  • 1
Marlon Fowler
  • 121
  • 3
  • 4
  • 15

2 Answers2

0

You can use these rules:

ErrorDocument 404 /page-not-found.html
ErrorDocument 403 /access-denied.html
SetEnv TZ America/Chicago

IndexIgnore *
Options -MultiViews

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)(?:.html)?$ /$1.php [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. – Marlon Fowler Feb 24 '14 at 20:46
  • Is it possible for you to check your Apache error log for the reason of this error. – anubhava Feb 24 '14 at 20:47
  • 1
    I use Godaddy as my hosting provider, if that helps. I've heard "Options MultiViews" is required if Godaddy is the host. – Marlon Fowler Feb 24 '14 at 20:47
  • Actually I had a typo. I just fixed it. Can you try again? – anubhava Feb 24 '14 at 20:59
  • It doesnt redirect, and also when I visit the page at www.3elementsreview.com/submission-guidelines.php the .php extension is still visible within the address bar. – Marlon Fowler Feb 24 '14 at 21:13
  • I just checked my error logs and there isn't anything in there. There are appache logs, and error logs, but nothing within error logs specifically. – Marlon Fowler Feb 24 '14 at 21:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48306/discussion-between-anubhava-and-marlon-fowler) – anubhava Feb 24 '14 at 21:22
  • I have already fixed 500 error reason so no need to check error.log now. – anubhava Feb 24 '14 at 21:24
0

The front controller pattern maybe is something could help you better.

That could help you to have /foo/bar and all will be handled by the index.php.

In case you can use .html instead of .php, editing the apache configuration with something like this could help:

AddType application/x-httpd-php .php .html .htm .your_ext
nbari
  • 25,603
  • 10
  • 76
  • 131