Redirection everything to index.php

╄→гoц情女王★ 提交于 2019-12-25 12:41:15

问题


I wan't to redirect everything to index.php exepept if a file or directory exists. I try'd a few ways from Google, but that really slowed the website down and don't really work so i amused that i got things wrong.

So URL like this:

    `site.com/Projects/S01/ -> site.com/Projects/S01/index.php (original)`
    `site.com/Projects/GE5/ -> site.com/Projects/GE5/index.php (original)`
    `site.com/Projects/     -> site.com/index.php`
    `site.com/Websites/     -> site.com/index.php`
    `sits.com/Testifcate/   -> site.com/index.php`

Whats the fastest way of doing this? All the methods I try'd are really slow. Thanks you. Files such as main.css are really slow at loading also, maybe those files don't go true the check to make it faster? What the best way to go about this?


回答1:


This is my rewrite rule that does just that:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]



回答2:


Try the following:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f # ensures it's not a file
RewriteCond %{REQUEST_FILENAME} !-d # ensures it's not a directory
RewriteRule . index.php [L,QSA] # . matches all, and routes to index.php if the above conditions do not match



回答3:


Does this work for you:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^$ http://domain.com/index.php [L,R=301]

I Hope it helps



来源:https://stackoverflow.com/questions/8161334/redirection-everything-to-index-php

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