开发者

Apache htaccess multiple rewritecond

开发者 https://www.devze.com 2023-03-18 16:40 出处:网络
I\'m having issues in writing rewritecond in the htaccess file on my web server. If someone could help me out, it would be very helpful to me.

I'm having issues in writing rewritecond in the htaccess file on my web server. If someone could help me out, it would be very helpful to me.

What I want to accomplish is these 2 things: 1. Redirect all requests to http: // domain.com to http: // www.domain.com 2. Redirect/ remove the index.html part from the URL if it exists.

My current htaccess 开发者_Go百科settings are:

Options +FollowSymlinks
RewriteEngine on

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ [b]http :// www. example. com[/b]/$1 [R=301,L]

What happens is that when the URL contains index.html, it basically gives a 404 page. Not sure where the redirects are looping. Cam someone chime in to shed some light on the issue?

Thanks in advance.


First rule tested out, second untested but should work. :)

Options +FollowSymlinks
RewriteEngine on

# redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.([a-z0-9\-]+)$ [NC]
RewriteRule ^/?(.*) http://www.%1.%2/$1 [R=301,L]

RewriteRule ^/?index\.html(\?.*)? /$1 [R=301]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号