mod_rewrites .htaccess 不适用于 godaddy 托管 (linux)

发布于 2024-12-28 19:42:20 字数 856 浏览 3 评论 0原文

在我的网站 www.sqcp.com 上,在另一台 Linux 服务器上进行测试,一切正常。然而,自从将其移至 godaddy 以来,mod_rewrites 一直无法工作,因此其他页面都无法访问。即使我在尝试整理其网址的内容中创建一个空白目录/文件夹,也适用于该页面(显然不是解决办法)。

因此,任何帮助都会对我的 .htaccess 文件很有帮助。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^index\.php$ / [L,R=301]

    RewriteRule (.*)/{2,}$ /$1/ [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
    RewriteRule (.*)\.php$ /$1/ [L,R=301]

    RewriteRule ^(.*)/(\d{4}\-\d{2}\-\d{2}\-[a-zA-Z0-9\-_]+)$ $1?s=$2 [L]

    RewriteRule ^(.*/)?staff.php/([a-zA-Z0-9\-_]+) $1staff.php?s=$2 [L]


    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule (.*)/$ $1.php [L] 

    RewriteCond %{REQUEST_FILENAME}/index.php !-f
    RewriteRule (.*)/$ $1 [L] 
</IfModule>

On my site www.sqcp.com in testing on another linux server, all worked as it should. However since moving it to godaddy, the mod_rewrites haven't been working, therefore none of the other pages have been accessible. Even if I create a blank directory/folder in the what it's trying to tidy the url to it then works for that page (obviously isn't a fix).

So any help would be great here my .htaccess file.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^index\.php$ / [L,R=301]

    RewriteRule (.*)/{2,}$ /$1/ [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
    RewriteRule (.*)\.php$ /$1/ [L,R=301]

    RewriteRule ^(.*)/(\d{4}\-\d{2}\-\d{2}\-[a-zA-Z0-9\-_]+)$ $1?s=$2 [L]

    RewriteRule ^(.*/)?staff.php/([a-zA-Z0-9\-_]+) $1staff.php?s=$2 [L]


    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule (.*)/$ $1.php [L] 

    RewriteCond %{REQUEST_FILENAME}/index.php !-f
    RewriteRule (.*)/$ $1 [L] 
</IfModule>

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

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

发布评论

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

评论(2

羅雙樹 2025-01-04 19:42:20

Godaddy 运行着一个非常好的共享托管服务,面向一个庞大的市场领域——想要一个活动站点(即带有一些脚本)但又不需要支付成本或复杂性或拥有管理自己的 Linux VM 的专业知识的用户。这不是 GoDaddy 的问题。它是你的。

因此,首先通过运行 phpinfo 脚本来了解您正在运行的环境,并确保它创建您使用的变量。据我在您的示例中看到的:

规则 1-3 是 301 重定向,以强制执行某些请求命名约定。

  • 规则 1 将 /index.php 重定向到 /
  • 规则 2 将尾部多个 / 折叠为单个 /
  • 规则 3 重写将 *.php 的 GET 请求转换为 *.php/

规则 4-6 将公共 URI 映射到内部

  • 规则 4 重写 /*/yyyy-mm-dd-词*?s=yyyy-mm-dd-word (注意没有 QSA)
  • 规则 5 似乎试图将 /*/staff.php/word 重写为 /*/staff.php?s=word 但语法是错误的。
  • 规则 6 在重定向时将任何尾随 / 替换为 .php
  • 规则 7 删除任何尾随 '/',除非 uri 是带有 index.php 的目录(我假设您是假设 DirectoryIndex index.php (GoDaddy 就是这种情况吗?)

这一切都令人困惑,您是隐藏还是公开 .php 扩展名?和 6 是规则 5 看起来更合乎逻辑,因为

RewriteRule ^(.*?)/staff.php/([a-zA-Z0-9\-_]+) $1/staff.php?s=$2 [L]

回到绘图板并弄清楚你想要如何使用你的公共 URI 语法;想要传递回客户端浏览器,您希望 Apache 作为内部重写进行处理,以及需要哪些额外条件来防止循环和误触发,确保这是有意义的,然后通过构建您的 .htaccess 在 a 处归档一条规则时间并使用测试请求依次执行每个规则以验证其作用。

Godaddy run a perfectly good shared hosting service, addressing a large market sector -- users who want an active site (that is with some scripting) but without the cost or complexity of paying for or having the expertise to administer their own Linux VM. This isn't a GoDaddy problem. Its yours.

So first get to understand the environment that you are running under by running a phpinfo script, and make sure it creates the variables that you use. As far as I can see on your example:

Rules 1-3 are 301 redirections to enforce some request naming convention.

  • Rule 1 redirects /index.php to /
  • Rule 2 collapses trailing multiple / to a single /
  • Rule 3 rewrites GET requests for *.php to *.php/

Rules 4-6 map public URIs to internal ones

  • Rule 4 rewrites /*/yyyy-mm-dd-word to *?s=yyyy-mm-dd-word (note no QSA)
  • Rule 5 seems to be attempting to rewrite /*/staff.php/word to /*/staff.php?s=word but the syntax is wrong for this.
  • Rule 6 replaces any trailing / by .php on redirection
  • Rule 7 strips any trailing '/' unless the uri is a directory with an index.php (I assume that you are assuming a DirectoryIndex index.php (is this the case for GoDaddy?)

This is all hopelessly confused. Are you hiding or exposing the .php extension? Because Rule 3,5 and 6 are inconsistent. And rule 5 would seem more logical as

RewriteRule ^(.*?)/staff.php/([a-zA-Z0-9\-_]+) $1/staff.php?s=$2 [L]

Go back to the drawing board and work out what you are trying to do with your htaccess rules; what you want your public URI grammar to be; how your scripts are laid out; what redirects you want to pass back to the client browser and which you want Apache to handle as internal rewrites and what extra conditions are needed to prevent looping and misfiring. Make sure this makes sense and then debug them by building up your .htaccess file one rule at a time and using test requests to exercise each rule in turn to validate what its doing.

寄居者 2025-01-04 19:42:20

尝试在 htaccess 文件的开头添加以下内容。我在 GoDaddy 上进行重写时遇到了同样的问题,而在其他地方都可以使用:

Options -Multiviews

Trying adding the following at the start of your htaccess file. I had the same problem getting rewrites to work on GoDaddy which worked everywhere else:

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