mod_rewrites .htaccess 不适用于 godaddy 托管 (linux)
在我的网站 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Godaddy 运行着一个非常好的共享托管服务,面向一个庞大的市场领域——想要一个活动站点(即带有一些脚本)但又不需要支付成本或复杂性或拥有管理自己的 Linux VM 的专业知识的用户。这不是 GoDaddy 的问题。它是你的。
因此,首先通过运行 phpinfo 脚本来了解您正在运行的环境,并确保它创建您使用的变量。据我在您的示例中看到的:
规则 1-3 是 301 重定向,以强制执行某些请求命名约定。
/index.php
重定向到/
/
折叠为单个/
*.php
的 GET 请求转换为*.php/
规则 4-6 将公共 URI 映射到内部
/*/yyyy-mm-dd-词
至*?s=yyyy-mm-dd-word
(注意没有 QSA)/*/staff.php/word
重写为/*/staff.php?s=word
但语法是错误的。/
替换为.php
DirectoryIndex index.php
(GoDaddy 就是这种情况吗?)这一切都令人困惑,您是隐藏还是公开
.php
扩展名?和 6 是规则 5 看起来更合乎逻辑,因为回到绘图板并弄清楚你想要如何使用你的公共 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.
/index.php
to/
/
to a single/
*.php
to*.php/
Rules 4-6 map public URIs to internal ones
/*/yyyy-mm-dd-word
to*?s=yyyy-mm-dd-word
(note no QSA)/*/staff.php/word
to/*/staff.php?s=word
but the syntax is wrong for this./
by.php
on redirectionDirectoryIndex 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 asGo 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.尝试在 htaccess 文件的开头添加以下内容。我在 GoDaddy 上进行重写时遇到了同样的问题,而在其他地方都可以使用:
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: