4

我一直在搜索 3 或 4 个小时没有任何结果(在搜索之前我玩了一个小时的规则但做不到)

我不知道你是否注意到,但谷歌使用 www 这样

当它没有子域时,它将是 www.google.com/blabla,当它有子域时,它将是 earth.google.com/blabla

这是第一部分

第二部分,正如你在 symfony 中所知道的,url 就像 domain.com/index.php/test 一样,感谢 symfony .htaccess 文件,你可以通过 domain.com/test 访问它所以这是我努力实现的目标

domain.com/test 重定向到 www.domain.com/test

www.sub.domain.com/blabla 重定向到 sub.domain.com/blabla

www.sub.domain.com/ 重定向到 sub.domain.com(没有任何 index.php XD)

我遇到的一个恼人问题是从 domain.com/ 重定向到 www.domain.com 后重定向它就像 www.domain.com/index.php (我讨厌 index.php :P)

那么有没有办法通过一个重定向来解决这个问题呢?我敢肯定我不是唯一一个需要这样的东西的人,并且可能对其他将使用 symfony 或其他框架的网站的人来说是一个想法谢谢

这是我完整的 htaccess 文件

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On

  # The admin subdomain returns to the backend
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{HTTP_HOST} ^admin\.mydomain\..*
  RewriteRule ^(.*)$ backend.php [QSA,L]

  # uncomment the following line, if you are having trouble
  # getting no_script_name to work
  #RewriteBase /

  RewriteCond %{HTTP_HOST} !^www.mydomain.com$
  RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301]

  # we skip all files with .something
  RewriteCond %{REQUEST_URI} \..+$
  RewriteCond %{REQUEST_URI} !\.html$
  RewriteRule .* - [L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
4

1 回答 1

1

在您的 VHOST 配置中:

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^/(.*) http://domain.com/$1 [R=301,L]

另请注意,从美学的角度来看,您可能更喜欢删除 www.,从技术角度(DNS、cookie 等)来看,最好使用 www. 作为前缀,并以相反的方式重定向。

于 2011-10-24T08:23:57.770 回答