apache - DirectAdmin Apache - .htaccess 重写

标签 apache .htaccess mod-rewrite url-rewriting directadmin

我在设置重写时遇到问题,希望有人知道答案。

这是我目前在 .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/

相关文章:

Apache RewriteRule 不适用

apache - mod_rewrite -> 未按预期工作

c# - 带有 C# 类的 Apache

apache - htaccess重写麻烦

.htaccess - htaccess 仅针对某些页面重定向到 ssl,而 www 对于其他页面不安全

wordpress - 通过 htaccess 的特定 Wordpress 页面 SSL 异常

mod-rewrite - 删除URL的一部分

java - 如何实现Android与HBase的连接?

java - Solr 和搜索运算符 - lucene apache solr

spring - 如何更改 Spring Data REST HATEOAS 链接中的主机名?