Forum Moderators: phranque
My ".htaccess" in \root as below
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ http://example.com/example/ [R=301,L]
The url shows as http://example.com/example/...
Question
I'd like to know how to make change in .htaccess and let the url show http://example.com/... without /example/
Thanks a lot!
By contrast, an internal rewrite simply changes the filepath associated with the requested URL, and serves the request from that new filepath; No communication with the client about the change takes place.
Because your code is in .htaccess, you'll also need to explicitly prevent looping. And because your RewriteCond accepts all possible hostnames, it doesn't do anything can be deleted. I also assume you want to rewrite requests for *all* resources in /root to /root/example, rather than just the index page. If this is not correct, then the code will need to be changed.
RewriteEngine on
RewriteCond $1 !^example/
RewriteRule (.*) /example/ [L]
Firstly, thanks for your help.
I read some previous post from you, finally understand the difference between external and internal redirect and
[R=] is for external redirect only. At present, The situation is there have more than one hostname share one hosting space in my case, so I could not rewrite requests for all resources in /root to /root/example.
I read the apache document and try to do some modification in .htaccess by myself, however I did not get the right way and feel so confusing.
could you give a help to do an example to achieve functions as below?
BEFORE
example01.com (Primary Domain) => root\ (as default)
example02.com ( Addon Domain )=> root\example02\ (as default)
AFTER
example01.com => root\example01\www\
www.example01.com => root\example01\www\
forum.example01.com => root\example01\forum\
example02.com => root\example02\www\
www.example02.com => root\example02\www\
forum.example02.com => root\example02\forum\
url shows without ...\example01\www\ ;ect..
Thanks a lot!
Which has higher RageRank and link popularity -- example01.com or www.example01.com?
Which has higher RageRank and link popularity -- example02.com or www.example02.com?
Jim
[edited by: jdMorgan at 12:08 am (utc) on June 19, 2008]
RewriteEngine on
#
########## Start to Canonicalize ##########
Rewritecond %{http_host} ^([^.]+\.com) [NC]
RewriteRule (.*) http://www.%1/ [R=301,L]
########## End of Canonicalize ##########
Then, the same way to each addon domain and theirs mainfolder.
Am i doing right with the code?
Furthermore, how to do the next part?(use flags P to define the internal path? how?)
This might work better:
RewriteEngine on
#
# Redirect non-canonical to canonical domains
# Skip next two rules if hostname is canonical
RewriteCond %{HTTP_HOST} ^(www¦forums)\.example01\.com$
RewriteRule .* - [S=2]
#
# Else if non-canonical "forums" subdomain, canonicalize it
RewriteCond %{HTTP_HOST} forums\.
RewriteRule (.*) http://forums.example.com/$1 [R=301,L]
#
# Else default to canonical www.example01.com hostname
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
www.example01.com => root\example01\www\which can be done with one rule:
forum.example01.com => root\example01\forum\
www.example02.com => root\example02\www\
forum.example02.com => root\example02\forum\
RewriteCond $1 !^(www¦forum)/
RewriteCond %{HTTP_HOST} ^(www¦forum)\.example01\.com$
RewriteRule (.*) /%1/$1 [L]
Replace the broken pipe "¦" characters in the patterns above with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim