将所有 URL 重写为 index.php,除了“/Serene/Assets/”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8543423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rewrite all URL to index.php except from '/Serene/Assets/'
提问by chintanparikh
So I've currently got all my URL's redirecting to index.php with this in my .htaccess:
所以我目前已经在我的 .htaccess 中将我所有的 URL 重定向到 index.php:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
However, I need URLs such as http://localhost/Portfolio/Serene/Assets/css/style.css
to not redirect, but I'm not sure how?
但是,我需要诸如http://localhost/Portfolio/Serene/Assets/css/style.css
不重定向之类的URL ,但我不确定如何重定向?
I'd really appreciate any help,
我真的很感激任何帮助,
Cheers.
干杯。
EDIT: Alternatively, I could tell the htaccess to not redirect any .js, .css, image files, etc, but again, I'm not too sure how to do this? Thanks!
编辑:或者,我可以告诉 htaccess 不要重定向任何 .js、.css、图像文件等,但同样,我不太确定如何执行此操作?谢谢!
EDIT2: I could also redirect anything ending in a .php or a path (such as /Portfolio/) to index.php, I have a feeling this may be easier.
EDIT2:我还可以将任何以 .php 或路径(例如 /Portfolio/)结尾的内容重定向到 index.php,我觉得这可能更容易。
EDIT3: Success, final code:
EDIT3:成功,最终代码:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT} !-f
RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php [QSA,L]
回答by SeanNieuwoudt
Here's a another way to do it:
这是另一种方法:
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
images, robots.txt won't be rewritten to index.php. Just add your directories/files.
图像,robots.txt 不会被重写到 index.php。只需添加您的目录/文件。
Hope that helps!
希望有帮助!
回答by Seventoes
This will rewrite requests for any files that don't exist on the server to index.php:
这会将服务器上不存在的任何文件的请求重写为 index.php:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]