简体   繁体   English

为什么.htaccess向我显示“内部服务器错误”?

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

In my site I removed .php extension from the url using .htaccess rules. 在我的网站上,我使用.htaccess规则从网址中删除了.php扩展名。 So that I can go to any page without .php extension. 这样我可以转到没有.php扩展名的任何页面。 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. 现在,我在php页面中有一个链接来更新表单数据。 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 : 我正在使用以下.htaccess规则:

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. 如果站点不在根域下运行,则yuo提供的.htaccess代码将无法正常运行。 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. 此代码块告诉服务器,任何以数字开头的以“ update”开头的URI都将被重写。 but in your case, the URI always starts with "aponit/dev/". 但是在您的情况下,URI始终以“ 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) 您将在线获得许多可用的教程,该教程如何基于服务器软件(XAMPP / WAMP等)来设置虚拟主机。

If you just want to remove .php from url, use the following code in .htaccess: 如果您只想从网址中删除.php,请在.htaccess中使用以下代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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