[英]How can I redirect multiple URLs to a single URL for the homepage?
我有一个基于codeigniter的网站,但遇到了一个小问题。 基本上,可以通过3个不同的URL访问主页,即:
www.domain.com/en
www.domain.com/en/
www.domain.com/en/home.html
我希望第一个和第三个URL重定向到第二个(www.domain.com/en/)。
我已经使用.htaccess玩了好几个小时,而且似乎无法完成任何更改。
任何帮助将非常感激。
编辑:这是我当前的.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
RewriteRule ^en(/home.html)?$ /en/ [L]
RewriteRule ^en(/home.html)?$ /en/ [L]
这仅匹配/ en和/en/home.html,不匹配其他网址。
您当前的解决方案不起作用,因为RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
已经捕获了所有输入RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
L
标志表示最后,这意味着不应再处理任何规则。
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Everything from here has to do with the line mentioned above
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L] # This catches all input
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
RewriteRule ^en(/home.html)?$ /en/ [L]
相反,您要处理的所有内容都需要在该行之前上移:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
RewriteRule ^en(/home.html)?$ /en/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
除此之外,在这里阅读mod_rewrite和正则表达式也无济于事。
就像改变一样简单
^en(/home.html)?$ /en/ [L]
至
^/en(/home.html)?$ /en/ [L]
(注意额外的斜杠)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.