开发者

Redirect everything to index.php

I'm tr开发者_开发技巧ying to do clean URLs by exploding $_SERVER['REQUEST_URI'] and then switching between the results.

However, once a user goes outside index.php, I'm assuming I need to redirect them back to index.php in order to process the URL they want to reach. How can I accomplish this?

So for instance, if the user goes to www.domain.com/home/johndoe/... I'd like index.php (domain.com/index.php) to be hit so that it can process the /home/johndoe/ via request_uri.


.htaccess:

RewriteEngine on
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?param=$1 [QSA,L]


You will need images, and other files what will show up in the index.php.

RewriteEngine On

Turns on the Rewite Engine

RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$

If the filename is not equal JPG, JPEG... which need for index.php

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

"Redirect" to index.php.

In use:

With PHP $_GET the q will give you the /articles/1987/12/20/Répa's birthday/

If you split the variable in every slash with

list($type, $date_year, $date_month, $date_day, $title) = split('[/-]', $_GET['q']);

You will got exactly what you want.


You can use Apache's mod_rewrite to map URLs based on regular expressions, including sending everything to index.php,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜