简体   繁体   English

mod_rewrite将根uri重定向到index.php

[英]mod_rewrite redirect root uri to index.php

I have a .htaccess file 我有一个.htaccess文件

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. 如果我输入网址www.domain.com/something以及已加载的CSS和JS文件,则效果很好。
The problem begins if i enter just www.domain.com (without any params) - browser displays blank. 如果我仅输入www.domain.com(不带任何参数),则问题开始-浏览器显示为空白。 What i need to add so that www.domain.com opens index.php and still all the css files will load? 我需要添加什么,以便www.domain.com打开index.php,仍然将加载所有CSS文件?

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) 但是它没有加载任何CSS文件,因为据我了解,它只是将所有内容都重定向到index.php(^ $而不是。也将所有内容都重定向到index.php)

I also tried adding at the beginning of index.php so www.domain.com would redirect at the php side 我还尝试在index.php的开头添加内容,这样www.domain.com就会在php端重定向

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]

Should load the CSS, javascript and images. 应该加载CSS,javascript和图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM