S.M_Emamian
S.M_Emamian

Reputation: 17383

How to Force domain to with www - htaccess

I'm using this htaccess to force all request with www. but my resources don't loaded:

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

this is my site:

http://www.shadyab.com/

for example:

http://www.shadyab.com/assets/plugin/slider/css/owl.carousel.min.css

Upvotes: 0

Views: 23

Answers (1)

Jon Lin
Jon Lin

Reputation: 143896

Your second rule rewrites everything to index.html, including all your css

If you really want to rewrite every request to index.html, but still want your resources, you can exclude them using a condition, otherwise remove the rule.

RewriteEngine on

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

RewriteCond %{REQUEST_URI} !\.(css|js|png|jpe?g|gif)$ [NC]
RewriteRule ^ /index.html [L]

Upvotes: 2

Related Questions