Mod Rewrite 在共享 Linux 服务器中无法使用 .htaccess 工作

发布于 2024-12-29 10:28:14 字数 797 浏览 1 评论 0原文

我正在使用共享的 Linux 主机,并创建了指向根文件夹内的 /hrms 文件夹的子域。

现在,我仅针对此子域设置了一个 mod 重写条件,如下所示:

RewriteEngine On
RewriteBase /hrms/
RewriteCond %{REQUEST_URI} !^/static/images
RewriteCond %{REQUEST_URI} !^/static/js
RewriteCond %{REQUEST_URI} !^/static/css
RewriteRule ^/(.*)$ /index.php?request=$1 [PT,QSA,L]

但是当我尝试登录时收到此错误:

http://hrms.atulmy.com/login

未找到 在此服务器上找不到请求的 URL /login。 此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

此外,我尝试检查 .htaccess 是否已解析,当我添加一些垃圾时,服务器给出了 500 内部错误,因此.htaccess 也被解析并且不是问题。

我已经在 google 和 stackoverflow 中搜索了相同的错误,但没有发现我正在做的错误。

请帮忙!谢谢...

阿图尔·亚达夫。 atulmy.com

I'm using a shared linux hosting and have created subdomain which points to /hrms folder inside the root folder.

Now, I've a mod rewrite condition for this subdomain only which goes like this:

RewriteEngine On
RewriteBase /hrms/
RewriteCond %{REQUEST_URI} !^/static/images
RewriteCond %{REQUEST_URI} !^/static/js
RewriteCond %{REQUEST_URI} !^/static/css
RewriteRule ^/(.*)$ /index.php?request=$1 [PT,QSA,L]

But I'm getting this error when I try to login:

http://hrms.atulmy.com/login

Not Found
The requested URL /login was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Also, I tried to check if .htaccess is parsed and when I added some junk, the server gave 500 Internal error, so .htaccess is also parsed and is not a problem.

I already searched for same error in google and stackoverflow, but didn't found the mistake I'm doing.

Please help! Thanks...

Atul Yadav.
atulmy.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

给不了的爱 2025-01-05 10:28:14

我假设您的共享托管服务 (SHS) 提供商提供了一些子域映射器控制台,以便完成 http://hrms.atulmy.com/~/hrms 的映射通过其 vhost 配置中特定于 SHS 的 RewriteMap

  1. 通过临时重命名 .htaccess 来验证您的假设;将 phpinfo 脚本放入 ~/hrms 中,并执行 http://hrms.atulmy.com/phpinfo.php
  2. http://hrms.atulmy 开始。 com/login 有一个 REQUEST_URI /login 您的 RewriteBase 应该只是 / 并且您应该使用 ~/hrms/ .htaccess
  3. 你永远不会匹配 .htaccess 重写规则中的 ^/
  4. 您应该在 .htaccess 重写规则中使用相对替换字符串,除非您想要重写到不同的目录层次结构。
  5. 您可能想要对 http://atulmy.com/hrms/ 进行正确的重定向
  6. 您不想在 index.php 上循环,因此您需要一个保护条件,最简单的方法是使用文件存在检查,这样就不需要现有的静态检查。

给予:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} =atulmy.com
RewriteRule hrms/(.*) http://hrms.atulmy.com/$1     [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)               index.php?request=$1 [PT,QSA]

如果您不喜欢这个,则将最后一个条件替换为:

RewriteCond %{REQUEST_URI} !^/static/(images|js|css)  [OR]
RewriteCond %{REQUEST_URI} !^/index\.php

I assume that your shared hosting service (SHS) provider provides some subdomain mapper console so the mapping of http://hrms.atulmy.com/ to ~/hrms is done through and SHS-specific RewriteMap in its vhost config.

  1. Verify your assumptions by temporarily renaming .htaccess; dropping a phpinfo script into ~/hrms and doing a http://hrms.atulmy.com/phpinfo.php
  2. Since http://hrms.atulmy.com/login has a REQUEST_URI /login your RewriteBase should be simply / and you should use ~/hrms/.htaccess
  3. You will never match ^/ in an .htaccess rewrite rule.
  4. You should use a relative substitution string in an .htaccess rewrite rule unless you want to rewrite to a different directory hierarchy.
  5. You might want to do a proper redirect of http://atulmy.com/hrms/
  6. You don't want to loop on index.php so you need a guard condition, the easiest way is to use a file existence check which removes the need for the existing static checks .

Giving:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} =atulmy.com
RewriteRule hrms/(.*) http://hrms.atulmy.com/$1     [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)               index.php?request=$1 [PT,QSA]

If you don't like this then replace this last condition by:

RewriteCond %{REQUEST_URI} !^/static/(images|js|css)  [OR]
RewriteCond %{REQUEST_URI} !^/index\.php
断桥再见 2025-01-05 10:28:14

这个怎么样:

RewriteEngine On
RewriteBase /hrms/
RewriteCond %{REQUEST_URI} !^/static/(images|js|css)
RewriteRule (.*) /index.php?request=$1 [PT,QSA]

?告诉我是否有效。

How about this:

RewriteEngine On
RewriteBase /hrms/
RewriteCond %{REQUEST_URI} !^/static/(images|js|css)
RewriteRule (.*) /index.php?request=$1 [PT,QSA]

? Tell me if it works.

牵你手 2025-01-05 10:28:14

你能发布更多你的 Htaccess 文件吗?如果我尝试:

http://hrms.atulmy.com/index.php?request=login

它会将我发送到:

http://hrms.atulmy.com/login

Can you post more of your Htaccess file? If I try:

http://hrms.atulmy.com/index.php?request=login

It sends me to:

http://hrms.atulmy.com/login
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文