如何通过index.php重新路由所有php页面请求?
我的.htaccess如下:
Options +FollowSymLinks
IndexIgnore */*
#Turn on the RewriteEngine
RewriteEngine On
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !.*\.(js|ico|gif|jpg|png|css|pdf)$ index.php%{REQUEST_URI} [L]
Run Code Online (Sandbox Code Playgroud)
基本上,我正在尝试模拟.NET母版页.index.php具有站点页眉/页脚.
它将404重定向到index.php.如何让它将所有请求重定向到php页面(index.php本身除外)?
此方法是否存在任何性能问题(不想使用框架)?
pow*_*uoy 20
这是我使用的(并且已经使用了很长时间):
<IfModule mod_rewrite.c>
# Redirect /index.php to / (optional, but recommended I guess)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php
RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
# Run everything else but real files through index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
正如评论所示,它会将每个不是实际文件的请求路由到index.php
使用:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php/params=$1 [L,QSA]
ErrorDocument 404 /index.php
网址样本:www.site.com/friend/josh/03-13-2012
所以$ params var值:
朋友/乔希/ 2012年3月13日
只需要explode()"/"所以你得到params数组:
array(
0 => friend
1 => josh
2 => 03-13-2012
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22034 次 |
| 最近记录: |