mod_rewrite将根uri重定向到index.php

问题描述:

我有一个.htaccess文件

I have a .htaccess file

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

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

如果我输入网址www.domain.com/something以及已加载的CSS和JS文件,效果很好.
如果我仅输入www.domain.com(不带任何参数),则问题开始-浏览器显示为空白.我需要添加什么,以便www.domain.com打开index.php,并且仍然会加载所有css文件?

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?

我尝试过

RewriteRule . /index.php [QSA,L] 

但是它没有加载任何CSS文件,因为我知道它只是将所有内容都重定向到index.php(^ $而不是.也将所有内容都重定向到index.php)

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)

我还尝试在index.php的开头添加内容,以便www.domain.com可以在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!

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

应加载CSS,javascript和图像.

Should load the CSS, javascript and images.