简体   繁体   English

Htaccess重写URL提供500内部服务器错误

[英]Htaccess rewrite url gives 500 Internal server error

I am getting 500 Error internal with following code : 我正在使用以下代码获取500 Error内部:

RewriteEngine On
RewriteRule ^([^/]*)$ /get.php?action=$1 [L]

The rewrite module is Active , Safe mode is OFF and there is no problem, 重写模块处于活动状态,安全模式关闭且没有问题,

I tested this code : 我测试了这段代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

But nothing changed. 但没有改变。

What to do now ? 现在做什么 ?

It looks to me the issue is that you're not setting any limits, so it loop's your redirect. 它在我看来问题是你没有设置任何限制,所以它循环你的重定向。

Here is an example that would stop since the file get.php exists. 这是一个自文件get.php存在以来会停止的示例。

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /get.php?action=$1 [L]

To further explain, what happens in your example is that it redirects to get.php over and over and over, because your rule tells anything not a / to internally redirect but not to stop if a file exits, and since get.php also falls under your regex expression, it would redirect again. 为了进一步说明,会发生什么在你的例子是,它重定向到get.php一遍又一遍又一遍,因为你的规则告诉任何东西不是一个/从内部重定向但不能停止,如果一个文件退出,并且自get.php也下降在你的正则表达式下,它会再次重定向。

What the 2 conditions I have added does is, it tells it to stop if a file or folder exists. 我添加的两个条件是,它告诉它停止文件或文件夹是否存在。

If you're using HTTPD version 2.4+ you could have simple used the flag [END] , like this: 如果您使用的是HTTPD版本2.4+,您可以使用标志[END]进行简单的使用,如下所示:

RewriteRule ^([^/]*)$ /get.php?action=$1 [END]

Which tells the server to stop any further redirects. 这告诉服务器停止任何进一步的重定向。

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

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