mod_rewrite redirect root uri to index.php

那年仲夏 提交于 2019-12-12 01:56:47

问题


I have a .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?q=$1 [QSA]

It works fine if i enter url www.domain.com/something and also css and js files ar loaded.
The problem begins if i enter just www.domain.com (without any params) - browser displays blank. What i need to add so that www.domain.com opens index.php and still all the css files will load?

I tried this

RewriteRule . /index.php [QSA,L] 

but it then none of css files are loaded because I understand that it simply redirects everything to index.php (^$ instead of . also redirects everything to index.php)

I also tried adding at the beginning of index.php so www.domain.com would redirect at the php side

header("Location: www.domain.com/begin");

but still it is not working because nothing is loaded!


回答1:


RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.php [L,R=302]

Should load the CSS, javascript and images.



来源:https://stackoverflow.com/questions/26679303/mod-rewrite-redirect-root-uri-to-index-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!