通配符子域和子文件夹在.htaccess参数 [英] Wildcard subdomain and subfolders as parameters in .htaccess

查看:299
本文介绍了通配符子域和子文件夹在.htaccess参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个门户网站 http://www.mysite.com/ ,客户报名参加,他们让网站运行我的应用程序自身的子域的版本。 我已经成立了通配符子域DNS /虚拟主机等,并得到它的工作。

I have a portal site http://www.mysite.com/ where customers sign up and they get their own subdomain version of the site to run my app. I've set up the wildcard subdomain DNS/VirtualHost etc and got it working.

我试图建立是我的htaccess文件传递通配符子域作为参数传递给应用程序,像这样的:

What I am trying to set up is my htaccess file to pass the wildcard subdomain as a parameter to the app, like this:

http://wildcardsubdomain.mysite.com/ -> http://www.mysite.com/app/?dj=wildcardsubdomain
http://wildcardsubdomain.mysite.com/?l=genres -> http://www.mysite.com/app/?dj=wildcardsubdomain&l=genres

我在 http://www.mysite.com/

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://www.mysite.com/app/dj/%1 [P,L]

不过,我需要重定向admin用户的网址如下,我已经得到了坚持与htaccess的code到/ app目录内使用。 我需要的是:

But I need to redirect the admin user URLs as follows and I've gotten stuck with the htaccess code to use inside the /app directory. What I need is:

http://wildcardsubdomain.mysite.com/admin/?l=genres -> http://www.mysite.com/app/admin.php?dj=wildcardsubdomain&l=genres
http://wildcardsubdomain.mysite.com/admin/?l=users -> http://www.mysite.com/app/admin.php?dj=wildcardsubdomain&l=users

(第l参数各不相同,我只是用用户和流派在这里作为一个例子)

(the l parameter varies, I've just used users and genres here as an example)

我已经试过这里面/app/.htaccess,但它未果然奏效:

I've tried this inside /app/.htaccess but it hasnt really worked:

RewriteRule ^dj/([^/]+)/?$ $2?dj=$1 [QSA,L]
RewriteRule ^admin/([^/]+)/?$ admin.php$2?dj=$1 [QSA,L]

任何人都可以提出一个更好的重写规则? 提前非常感谢

Can anyone suggest a better rewrite rule? Many thanks in advance

推荐答案

你错过了一个 QSA 标记,因为 L =类型丢失,否则。你的其他规则之前,你只需要一个管理员的规则:

You're missing a QSA flag, as the l=genres gets lost otherwise. You just need an "admin" rule before your other rule:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^admin/?$ http://www.mysite.com/app/admin.php?dj=%1 [P,L,QSA]

RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).mysite.com
RewriteRule ^([^/]*)$ http://www.mysite.com/app/dj=%1 [P,L,QSA]

这篇关于通配符子域和子文件夹在.htaccess参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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