我的 htaccess RewriteRule 适用于 localhost/mysite 但不适用于 1&1 共享主机上的 mysite.com [英] My htaccess RewriteRule works on localhost/mysite but not at mysite.com on a 1&1 shared host

查看:14
本文介绍了我的 htaccess RewriteRule 适用于 localhost/mysite 但不适用于 1&1 共享主机上的 mysite.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,解决方案并不令人满意.今天早上,在尝试@Wige 的建议时,令我惊讶的是,预期值实际上作为 GET 查询发送到页面.显然,1&1(我知道他们在过去几周一直在改变他们的环境)在幕后做了一些神奇的事情,解决了我的问题,现在我以前无法运行的所有代码都可以正常工作正如最初预期的那样.

unfortunately, the solution is not a satisfying one. This morning, when trying @Wige's Suggestion, I found, to my suprise, that the Expected values WERE infact sent to the page as a GET query. Apparently, 1&1 (who I know have been making changes to their environment this last couple weeks), did something behind the scenes which magically fixed my problem, and now all of my previously unworking code is working as originally expected.

新信息:生产服务器的 Apache 版本是 1.3.342.2.21 在我的 localhost 上.

New info: The Apache version of the production server is 1.3.34 vs 2.2.21 on my localhost.

我无法弄清楚为什么我的 RewriteRule 在生产中无法正常工作.

RewriteRule ^page/pretty-url/(.*)$ page.php?query=$1 [L]

在我的本地测试环境 (localhost/mysite/page/pretty-url/{...}) 中它工作正常,但在 mysite.com/page/pretty-url/{...} 它不能正常工作.它按预期加载 page.php 但显然 ?query=$1 部分被忽略($_GET 为空)

In my local testing environment (localhost/mysite/page/pretty-url/{...}) it works fine, but on mysite.com/page/pretty-url/{...} it doesn't work properly. It loads page.php as expected but apparently the ?query=$1 piece is ignored ($_GET is empty)

我认为问题与服务器配置有关.我使用的是 1&1 共享主机帐户,没有 httpd.conf 访问权限.

I imagine that the problem is somehow related to the server configuration. I'm on a 1&1 shared hosting account with no httpd.conf access.

RewriteRule 做什么(或应该做什么):

What that RewriteRule does (or should do):

我想要像这样的网址

*example.com/page/pretty-url/{{info_for_dynamic_content}}

改写为

*/page.php?query={{info_for_dynamic_content}}

所以我可以访问info_for_dynamic_content

So I can access info_for_dynamic_content

php 中作为 $_GET['query']

完整的 .htaccess 文件供参考:

AddHandler x-mapp-php6 .php

DirectoryIndex index.php
ErrorDocument 404 /index.php 

Options +FollowSymLinks

# per @Jacques Chester's suggestion
Options -MultiViews

RewriteEngine on
RewriteBase /

# the rule in question
RewriteRule ^page/pretty-url/(.*)$ page.php?query=$1 [L]

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*)$ $1.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php !-f 
RewriteRule (.*) /index.php [L]

推荐答案

很可能,您的主机将变量存储在其他地方.我会添加对 phpinfo() 的调用;进入您的脚本并查看那里的环境变量,看看您是否可以找到应该在 get 中的值.

Most likely, your host is storing the variables somewhere else. I would add a call to phpinfo(); into your script and go through the environment variables there to see if you can find the values that should have been in get.

这篇关于我的 htaccess RewriteRule 适用于 localhost/mysite 但不适用于 1&1 共享主机上的 mysite.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆