开发者

Internal redirect from subdomain to root via .htaccess

I use following .htaccess-code to convert my URLs to user-friendly ones:

RewriteEngine on
RewriteRule ^(.*)/$ index.php?page=$1

Now I want to redirect requests from the www-subdomain to the rootdomain, e.g. if the user requests http://www.mydomain.com/stuff/, he gets to see http://mydomain.com/stuff/ in the address bar of his browser.

All attempts I've made resulted in external redir开发者_StackOverflow中文版ects, so the user gets to see the rewritten URL, e.g. http://mydomain.com/index.php?page=stuff.

How do I perform an internal redirect, so that the address bar doesn't change?


Use these rules (put them into .htaccess file in root folder):

RewriteEngine On
RewriteBase /

# canonical domain name (no www please)
RewriteCond %{HTTP_HOST} =www.domain.com
RewriteRule ^(.*)$ http://domain.com/$1 [QSA,R=301,L]

# nice url handler
RewriteRule ^(.*)/$ /index.php?page=$1 [QSA,L]

You most likely had the correct rules already (based on your description) .. you just had them in wrong order. You have to keep in mind -- order matters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜