带有嵌套 .htaccess 文件的 mod_rewrite
我已经在我的根目录中创建了一个 .htaccess
来创建子域级别,假设它是 sub.domain.ex
重定向到 domain.ex/deb/
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} sub.domain.ex
RewriteCond %{REQUEST_URI} !deb/
RewriteRule ^(.*)$ /deb/$1 [L]
这效果很好。
现在,我转到 /deb/
并创建另一个 .htaccess
,其中
RewriteEngine on
RewriteRule ^([^/]+)/ /deb.php?app=$1 [NC]
deb.php 是一个打印参数“app”的文件。 它有效,但前提是我调用 http://sub.domain.ex/something/
(注意末尾的斜杠)。它仅适用于最后一个斜杠,如果我删除它,它就不起作用,并且我希望它在没有最后斜杠的情况下工作。
所以我将规则更改为 ^([^/]+)
但现在我有 500 Apache 内部错误。 正则表达式教练在我身边进行选择,也许我错过了一些东西。 谢谢
更新
我快疯了。 Mybe 将一个 .htaccess 放在根目录中用于创建第三个子级别域并将 .htacces 放在另一个目录中是错误的吗?因为我正在尝试一些技巧。 使用此规则
RewriteEngine on
RewriteRule ^([^/]+)/ deb.php?app=$1 [NC]
我在 /deb
目录的 .htacces 中 ,并创建了 print_r($_GET);
并调用了 index.php。因此,如果重定向将我转发到 cydia sublvel 的 index.php 并且不采用 /deb/deb.php! 回顾一下。 我的目录结构是这样的:
/htdocs/ -> the root of the main domain level like www.example.com
---index.php -> home file of www.example.com
/htdocs/deb -> the root directory of the 3th sublevel domain (subdomain.example.com ->
---index.php
---deb.php
因此,第三级域的 .htaccess 位于 /htdocs./htaccess 中,并如前所述。 另一个用于“美化”链接的 .htaccess 位于 /htdocs/deb/.htaccess 中。我希望当你转到 subdomain.domain.com/someText 时它会转换为 deb.php?app=someText
现在我尝试转到 subdomain.domain.com/deb.php....WTF!? deb.php 位于 /htdocs/deb/deb.php
主页很清楚
I have made an .htaccess
to my root directory for creating a subdomain level, assume it is sub.domain.ex
that redirect to domain.ex/deb/
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} sub.domain.ex
RewriteCond %{REQUEST_URI} !deb/
RewriteRule ^(.*)$ /deb/$1 [L]
and this works well.
Now, I go to /deb/
and create another .htaccess
with the following
RewriteEngine on
RewriteRule ^([^/]+)/ /deb.php?app=$1 [NC]
the deb.php is a file that prints the argument "app".
It works but only if i call http://sub.domain.ex/something/
(note the slash at the end). It only works with a final slash, if I remove it, it doesn't and I want it to work without final slash.
So I change the rule into ^([^/]+)
but now I have 500 Apache internal error.
The regex coaches are by my side with the selection, maybe I'm missing something.
Thanks
UPDATE
I'm runinng mad. Mybe is wrong to put one .htaccess in the root for creating se 3th sublevel doman and the .htacces in the other directory? Because I'm ttrying some trick.
I use this rule
RewriteEngine on
RewriteRule ^([^/]+)/ deb.php?app=$1 [NC]
in the .htacces of the /deb
directory and made a print_r($_GET);
and called index.php. So the redirectory doesn't work at all if it forward me on the index.php of the cydia sublvel and doesn't take the /deb/deb.php!!!
Recap.
my dir structure is this:
/htdocs/ -> the root of the main domain level like www.example.com
---index.php -> home file of www.example.com
/htdocs/deb -> the root directory of the 3th sublevel domain (subdomain.example.com ->
---index.php
---deb.php
So the .htaccess for the 3th level domain is the in /htdocs./htaccess and described as before.
The other .htaccess for "beautify" the link is in the /htdocs/deb/.htaccess. I want that when you go to subdomain.domain.com/someText it transform to deb.php?app=someText
Now i tryed go to subdomain.domain.com/deb.php....WTF!? the deb.php is in /htdocs/deb/deb.php
Home is clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
至少,假设我理解你想要的一切,这对我来说效果很好。
在
/htdocs/.htaccess
中:在
/htdocs/deb/.htaccess
中:编辑: 我更新了第二个文件的内容以反映您的其他请求。如果您不希望它们能够转到
sub.domain.ex/something/ ->,您应该删除
。/?
deb.php?app=somethingThis works fine for me, at least, assuming I understood everything you wanted.
In
/htdocs/.htaccess
:In
/htdocs/deb/.htaccess
:Edit: I updated the second file's contents to reflect your additional requests. You should remove the
/?
if you don't want them to be able to go tosub.domain.ex/something/ -> deb.php?app=something
.我可能是错的,但在第二个 .htaccess 中,您应该检查 url 是否尚未用“/deb.php”重写,
所以类似
I could be wrong, but in the second .htaccess you should check that the url wasn't yet rewrited with "/deb.php"
So something like
您重写规则应该是
这是 Drupal 等 CMS 中使用的常见模式
You rewrite rule should be
That's a common pattern used in CMSs like Drupal
我认为我的主人受到了某种限制。这是不可能的。我尝试了所有类型的 goo(对于 regexcoach)来匹配正确的组,并且没有其他 500 错误 apache。
让它工作的唯一方法是使用 tu 参数
使用此
^app/([^/]+) /deb.php?app=$1
并使用sub.domain.com/app/nameTest
进行调用,这是有效的带或不带结尾反斜杠。如果您得到一些摆脱此问题的建议,请告诉我。
再见
I think there is some kind of rescrctions to my host. It's impossible. I tried all kind of goo (for a regexcoach) for matching the correct group and there is nothing else the 500 error apache.
The only way to get this to work is use tu parameters
with this
^app/([^/]+) /deb.php?app=$1
and calling withsub.domain.com/app/nameTest
and this is working with or without the end backslash.Of you get some advice for getting rid of this, please let me know.
bye