我在设置重写时遇到问题,希望有人知道答案。
这是我目前在 .htaccess 中使用的代码:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /point/to/dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+/.*)$ https://domain.ext/point/to/dir/module/status.php?id=$1 [L,QSA]
客户端正在向服务器请求domain.ext/point/to/dir/,应该重写为https://domain.ext/point/to/dir/module/status.php .
有可能在/point/to/dir/请求的末尾添加了查询,应该附加到https://domain.ext/point/to/dir/module/status.php ./point/to/dir/是服务器上不存在的位置。
无论我做什么,我都会收到内部服务器错误(不正确的 .htaccess 配置/语法)或 404。希望有人能帮忙。
最佳答案
使用您显示的示例,按照以下方式获取您的 htaccess 规则文件。确保将路径从 point/to/dir
更改为您的实际路径(不要将 /
放在它前面,否则规则将不起作用)。
这是假设您的 point/do/dir 在模块文件夹中也有模块文件夹和 index.php。
确保在测试您的 URL 之前清除您的浏览器缓存。
Options +FollowSymLinks
RewriteEngine on
RewriteBase /point/to/dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(point/to/dir)/(.*)/?$ https://domain.ext/$1/module/status.php?id=$2 [NC,L,QSA]
OR 如果您使用相同的域名,那么您无需在重写的右侧部分提及完整的 url,然后按照以下方式使用,确保要么使用一次只能高于或遵守规则。
Options +FollowSymLinks
RewriteEngine on
RewriteBase /point/to/dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(point/to/dir)/(.*)/?$ $1/module/status.php?id=$2 [NC,L,QSA]
关于apache - DirectAdmin Apache - .htaccess 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68358903/