问题描述
我在设置重写时遇到问题,希望有人知道答案。
这是我目前在 .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,QSA]