我是htaccess的新手,我一整天都在努力。请帮忙。我只想要:
这是我从typo3网站上复制的htaccess文件:
<FilesMatch "\.(js|css)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 7 days"
</IfModule>
FileETag MTime Size
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} !^dnaplus-humangenetikaicentrum\.com$
RewriteRule ^(.*)$ http://dnaplus-humangenetikaicentrum.com/hu/$1 [L,R=301]
它将www.example.com重定向到www.example.com/hu。但不适用于example.com。
答案 0 :(得分:0)
试试这个
# if hostname starts with "www"...
RewriteCond %{HTTP_HOST} ^www\.(.+)$ #here we get rest of URI as %1
# ...redirect permanently to hostname whitout "www":
RewriteRule (.*) http://%1/$1 [R=301,L]
# if client requested root directory:
RewriteCond %{REQUEST_URI} ^/$
# redirect him to start page:
RewriteRule .* hu [R=307,L]
我建议使用exacly临时重定向(307)来启动页面。浏览器会对301状态进行硬缓存,因此如果您稍后更改起始页,某些用户仍会被重定向到旧页面。