1
  1. How do i redirect a url to domain . eg. http://www.mydomain.com/index.php=HairThing --> http://www.mydomain.com

  2. How do i redirect a non-www to www WITHOUT a slash at end ?

eg http://mydomain.com ---> http://www.mydomain.com

4

3 回答 3

4

See also: Hidden features of mod_rewrite

#1
RewriteRule /index.php=HairThing$ http://www.mydomain.com [R=301]

#2
RewriteCond %{HTTP_HOST} ^mydomain.com 
RewriteRule .*   http://www.mydomain.com [R=301] 

However, example case 1, as said by Greg, will always put the / on if it is without a uri.

mydomain.com  # impossible 
mydomain.com/ # possible
mydomain.com/foo  #possible
mydomain.com/foo/ #possible
于 2008-12-10T07:22:04.773 回答
2

For your second question, the browser will always put a slash after the site name. This is because the trailing slash is required to indicate the root path of the web site.

于 2008-12-10T07:21:37.533 回答
0

您可以使用适用于每个域的通用规则,而不必一直更改域的名称。当您将多个域停放在同一个根目录上时,这非常有用。

RewriteCond %{HTTP_HOST}    !^www\.[a-z0-9-]+\.[a-z]{2,6}   [NC]
RewriteCond %{HTTP_HOST}    ([a-z0-9-]+\.[a-z]{2,6})$       [NC]
RewriteRule (.*)            http://www.%1/$1                [L,R=301]
于 2009-04-01T11:32:11.590 回答