简体   繁体   中英

why .htaccess is showing me “Internal Server Error”?

In my site I removed .php extension from the url using .htaccess rules. So that I can go to any page without .php extension. eg :

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM