.htaccess 将URL重写到其他目录并更改扩展名

.htaccess 将URL重写到其他目录并更改扩展名,.htaccess,.htaccess,我有一个问题,一些重写,我已经广泛检查了: 但是在web服务器上,它并没有像预期的那样工作 我的规则是: ReWriteEngine On RewriteRule ^$ /content/index.php [L] RewriteRule ^(.*)/(.*).html$ /content/$1/$2.php [L] RewriteRule ^(.*)/$ /content/$1/index.

我有一个问题,一些重写,我已经广泛检查了:

但是在web服务器上,它并没有像预期的那样工作

我的规则是:

ReWriteEngine On

RewriteRule ^$                  /content/index.php          [L]
RewriteRule ^(.*)/(.*).html$    /content/$1/$2.php          [L]
RewriteRule ^(.*)/$             /content/$1/index.php       [L]
RewriteRule ^(.*)$              /content/$1/index.php       [L]
示例URL为:

https://domain.tld -> /content/index.php
https://domain.tld/ -> /content/index.php

https://domain.tld/path -> /content/path/index.php
https://domain.tld/path/ -> /content/path/index.php
https://domain.tld/path/page.html -> /content/path/page.php

https://domain.tld/path/more -> /content/path/more/index.php
https://domain.tld/path/more/ -> /content/path/more/index.php
https://domain.tld/path/more/page.html -> /content/path/more/page.php
我得到一个内部服务器错误,即使页面上没有任何内容。如果我删除路由,我会得到404罚款


谢谢你的帮助。如果需要更多信息,请询问。

检查.htaccess文件顶部的规则

RewriteEngine on
RewriteBase /content/

# path/more/page.html -> /content/path/more/page.php
RewriteRule ^(.*)\/(.*)\/(.*)\.html$    /$1/$2/$3.php  [L]

# path/more/ -> /content/path/more/index.php
RewriteRule ^(.*)\/(.*)\/$    /$1/$2/index.php  [L]

# path/page.html -> /content/path/page.php
RewriteRule ^(.*)\/(.*)\.html$    /$1/$2.php  [L]

# path/more -> /content/path/more/index.php
RewriteRule ^(.*)\/(.*)$    /$1/$2/index.php  [L]

# path/ -> /content/path/index.php
RewriteRule ^(.*)\/$    /$1/index.php  [L]

# path -> /content/path/index.php
RewriteRule ^(.*)$    /$1/index.php  [L]

# / -> /content/index.php
RewriteRule ^\/$    /index.php  [L]

# https://domain.tld -> /content/index.php
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.tld [NC]
RewriteRule ^ /index.php [L]

那么,http服务器的错误日志文件说明了实际问题是什么呢?啊,显然,使用上述设置会得到一个重定向循环。任何重写的请求都会被一次又一次地重写,因为您无条件地重写了所有内容。