In my site I removed .php extension from the url using .htaccess rules. So that I can go to any page without .php extension. e.g :
http://localhost/aponit/dev/zones (there are no .php extension)
Now,I have a link in a php page to update a form data. Link is bellow :
<a class="btn btn-success btn-xs" href="<?php echo SITE_URL."update/$zone_id"?>" >Edit</a>
This link showing following url :
http://localhost/aponit/dev/update/54
But unfortunately It's showing me error message :
Internal Server Error
I am using following .htaccess rules :
ErrorDocument 404 /not-found.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^update/([0-9]+) update?z=$1 [L]
Trying to:
ErrorDocument 404 /not-found.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
And post detail log file???
The .htaccess code that yuo have provided will not work correctly if the site does not run under root domain. For example
RewriteRule ^update/([0-9]+) update?z=$1 [L]
This code block tells the server that any URI starting with "update" following a number will be rewritten. but in your case, the URI always starts with "aponit/dev/". So this code will not work any time.
Solution
Set up a virtual host. You will get a lot of available tutorials online how to setup a virtual host based on your server software(XAMPP/WAMP etc)
If you just want to remove .php from url, use the following code in .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Related
I removed the php directory from my URL and remove the .php extension.
But now I am trying to add my 404/500 error to make my website look nice.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /php/$1 [QSA,L]
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
When I redirect the errorDocument to an external page it works but not to my local file. I get a 500 Internal Server error. I could make a workaround and just make it go to an external page what will be my page. But that's not really clean.
Is anyone able to help me with this?
I think you must match against DOCUMENT_ROOT as well as add this RewriteCond %{REQUEST_FILENAME}\.php -f before adding .php like this :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/php%{REQUEST_URI}\.php -f
# or you could do it like this
# RewriteCond %{DOCUMENT_ROOT}/php%{REQUEST_URI} -f
# without php according to your setting
RewriteRule ^(.*)$ /php/$1 [QSA,L]
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
because whenever you send wrong request to any target destination you must make sure that target will handle it and there are enough conditions to classify which one should go , otherwise server will generate error.
I have following file in root directory :
Dev (root)
update.php
zones.php
This zones.php file is showing using following url:
http://localhost/aponit/dev/zones (I hide .php extension using .htaccess rules)
In zones.php file I have a edit link to edit a form via query string. The link is bellow :
<a class="btn btn-success btn-xs" href="<?php echo SITE_URL."zones/update?z=$zone_id"?>" >Edit</a>
When I click on this link it's showing following url :
http://localhost/aponit/dev/zones/update?z=55
But in browser it's showing me error message :
Internal Server Error
Because my .htaccess rules is not define appropriate rules for that desired link.
What I want now :
I want the url should be user friendly. E.g
http://localhost/aponit/dev/zones/update/55
How can I create this link using .htaccess ?
Current .htaccess rules :
ErrorDocument 404 /not-found.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
You can have another rule to handle zones/update/55:
Options -MultiViews
ErrorDocument 404 /not-found.php
RewriteEngine on
RewriteRule ^(?:zones/)?update/(\w+)/?$ update.php?z=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I am trying to remove the ".php" on my website. I have changed the .htaccess file based on the documentation provided in the dreamhost wiki to the following:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
However, this does not work on the site. For example this code does not work:
link
It shows the following error:
Not Found
The requested URL /jimmyvosler.com/public/about.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This works (but still displays the .php at the end, which is what im trying to fix):
link
I don't understand what is causing this, especially since the error even points to the correct place. Is there a setting I need to check on my admin tool?
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Here is the solution for anyone else that has the same trouble. I added this to my .htaccess file. This solution came from dreamhost support and was linked from this website: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Try this:
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]
Hi i have my htaccess with this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.htm [L]
ErrorDocument 404 /404.htm
if i erase the first 4 lines, the other piece of code (which redirects de 404 page when there's a page not found) does not work anymore.
Any ideas?
I also want that when it redirects to 404.htm, it does not show on the url box, this url
http://www.mypage.com/404.htm
i want to show this
http://www.mypage.com/fail/search-by-the-user
for example.
Try following .htaccess
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /$1.html
ErrorDocument 404 /404.html
NOTE: if you are working at localhost then please mention proper RewriteBase
I'm trying to accomplish 2 things in my .htaccess:
Redirect all requests for (in example) www.blanklabs.com/boarddrive/faq, www.blanklabs.com/boarddrive/faq.htm, www.blanklabs.com/boarddrive/faq.html, or www.blanklabs.com/boarddrive/faq.php to www.blanklabs.com/boarddrive/faq.php
The browser's address bar should show just www.blanklabs.com/boarddrive/faq, without the extension.
Here is my current .htaccess:
RewriteEngine On
# -- new
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L,QSA]
On the server I have faq.html (for now), but I also tried having both faq.html and faq.php. Eventually it'll just be faq.php.
The .htaccess is clearly incorrect, since if I go to www.blanklabs.com/boarddrive/faq.html I get the correct content (from faq.html), but if I go to www.blanklabs.com/boarddrive/faq.php I get a 500 error. This happens even if I have faq.php on the server.
Any ideas what I'm doing wrong? The no-extensions is secondary, the primary goal is to redirect all requests from html to php files.
Place this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# skip POST requests
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.(php|html?)[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)(\.html?)?$ /$1.php [L,QSA]
You need to redirect
/faq.htm
/faq.php
[using redirect directive]
to /faq
now just applying rewrite rule to this later condition [/faq] to
/faq.php
It should work.