开发者

Help On Programming .htaccess to redirect to controller

I need to convert the following where website url that user inputs ,

var1 is a wildcard set by user to login to his account details.

http://var1.domain.com/var2/var3

redirect to:

http://domain.com/master5.php?uid=var1&wid=var2&camid=var3

and another rule i need is

var1.domain.com/var2/

redirect to:

doma开发者_如何学Cin.com/master5.php?uid=var1&wid=var2

if possible I need to cloak them too so user actually only see

var1.domain.com/var2/var3


I'm not great at preg expressions, but what you're looking for is something like this

RewriteCond %{REQUEST_URI} .*\.domain\.com/.*/.*$ [NC]
RewriteRule ^(.*)\..*/(.*)/(.*)$ master5.php?uid=$1&wid=$2&camid=$3
RewriteCond %{REQUEST_URI} .*\.domain\.com/.*/$ [NC]
RewriteRule ^(.*)\..*/(.*)/$ master5.php?uid=$1&wid=$2

The conidition determines whether the rule should run, and the rule says how to translate the URL provided into the actual URL you wish to execute. You may wish to try and refine the preg into precisely what you want using something like http://regextester.com/ to fine tune it.

Edit: Note, you must have setup your DNS entry for *.domain.com rather than for www.domain.com otherwise no subdomains will be passed through to your server anyway.


I got it working but the last rule does not pass the subdomain variable when I enter http://something.domain.com

Options +FollowSymLinks RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ http://www.domain.com/master5.php?username=%2&$1&$2
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ http://www.domain.com/master5.php?username=%2&$1&$2

RewriteRule ^$ http://www.domain.com/profile.php?username=%2 [L]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜