开发者

.htaccess redirect subdomain to a page in parent domain + query

开发者 https://www.devze.com 2023-03-17 05:35 出处:网络
I am trying to redirect all (dynamic)subdomains to a page with querystring but it\'s giving page not found error.

I am trying to redirect all (dynamic)subdomains to a page with querystring but it's giving page not found error. Any ideas pls? Eg. Woul开发者_运维问答d like something like

http://foo.example.com

to redirect to

http://www.example.com/pagefile.php?member_id=foo

I would appreciate if it retains the subdomain URL format.

# Make PHP code look like other code types
    AddType application/x-httpd-php .asp .py .pl


    <Files php.ini>
    order allow,deny
    deny from all
    </Files>

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(\w+)\.mivasite\.com [NC]
RewriteRule .* http://example.com/pagefile.php?member_id=$1


You're mixing up the capture groups in your rewritecond and rewriterule. The matches in RewriteCond are stored in %1, %2, etc... while $1, $2 etc... are the captures from RewriteRule.

You're not doing any capturing in the RewriteRule, so $1 will be blank. Try doing

RewriteRule .* http://mivasite.com/pagefile.php?member_id=%1

instead. Of course, That probably won't fix your 404 error, as this will merely fix up the query parameter. Check your server's error log to see exactly what the URL was that produced the 404 error.

0

精彩评论

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