尝试调试 .htaccess 文件

Trying to debug .htaccess file

我开始使用 PHP 网页的 mod_rewrite 功能

我非常兴奋地创建了我的第一个重写规则,但是当我添加到我的 .htaccess 文件时,所有网页(不仅仅是我尝试重定向的网页)都出现错误 500。

这是我的文件:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^([^/]*)/(([^/]*)/)*$
RewriteCond %{REQUEST_FILENAME}index.php !-f
RewriteCond %{REQUEST_FILENAME}index.html !-f
RewriteCond %{REQUEST_FILENAME}index.htm !-f
RewriteRule ^/([a-zA-Z\-]+)\/([a-zA-Z\-]+)\/([0-9]+)$ ficha_jugador.php?idjugador= [L]
RewriteRule (.*) /index.html [L]

我的新行是第 8 行,其余的默认来自我的网络服务器

我在第 8 行尝试了一些更简单的东西来测试

RewriteRule ^writetest\.html http://www.after5pc.net [QSA,L]

不过也以500错误告终,看来不是语法问题

最终,我想做的是更改(删除我的 URL)

http://cadistas1910.com/ficha_jugador.php?idjugador=1304
by
http://cadistas1910.com/alvaro-garcia-canto/alvaro-garcia/1304

你们能提供什么帮助吗?非常感谢!

我认为您的 .htaccess 文件的最后一行可能是罪魁祸首,请您尝试执行一次。

RewriteEngine On
RewriteBase /

RewriteRule ^([a-zA-Z\-]+)\/([a-zA-Z\-]+)\/([0-9]+)$ ficha_jugador.php?idjugador= [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]

当且仅当 Uri 不存在 directory/file 时,我在那里添加了重写为 index.html 的条件,因为它会创建一个没有条件的无限循环,因为你正在重写所有内容到 index.html 并且所有内容(通过正则表达式)也匹配 index.html,因此出现循环和 500 内部错误。

您从 http://localhost:80/alvaro-garcia-canto/alvaro-garcia/1304 重写到 http://localhost:80/ficha_jugador.php?idjugador=1304 的规则也已更改为上面的一行。

注意: 要解决此问题,请将链接设置为绝对链接或使用基本标记。在您网页的 header 中添加此 <base href="/"> 以便您的相关链接可以从正确的位置加载。