RewriteRule创建500内部服务器错误

编程入门 行业动态 更新时间:2024-10-28 18:24:38
本文介绍了RewriteRule创建500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

.htaccess文件中包含以下内容:

I have the following in my .htaccess file:

Options +FollowSymLinks RewriteEngine on RewriteRule ^directory/(.*)$ directory/index.php?id=$1

我要实现的目标是:

访问URL www.mydomain/directory/10时,浏览器上将显示页面www.mydomain/directory/?id=10,而不会更改URL的外观.

When the URL www.mydomain/directory/10 is visited, the page www.mydomain/directory/?id=10 is displayed on the browser without altering the appearance of the URL.

上面的代码虽然会创建500个内部服务器错误.

The above code creates a 500 Internal server error though.

有人知道我要去哪里吗?

Does anyone know where I'm going wrong?

推荐答案

由于您的代码会导致无限循环,因此可以确保您的代码生成500个内部服务器错误.原因是您匹配的URI模式为:^directory/(.*)$

Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^directory/(.*)$

在重写前后匹配您的URL.并且一旦达到最大允许的内部重写限制,Apache就会抛出500个内部服务器错误并纾困.

Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.

将代码更改为此:

Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^directory/(.*)$ /directory/index.php?id=$1 [L,QSA,NC]

上面的代码还有一个额外的RewriteCond %{REQUEST_FILENAME} !-f,这将确保在第一次之后不允许RewriteRule的后续执行,因为/directory/index.php将是有效文件.

Above code has an extra RewriteCond %{REQUEST_FILENAME} !-f that will make sure to disallow subsequent execution of RewriteRule after first time since /directory/index.php will be a valid file.

更多推荐

RewriteRule创建500内部服务器错误

本文发布于:2023-11-01 23:48:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   服务器   RewriteRule

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!