How to redirect everything internally using htaccess and mod_rewrite?
I want to process all the requests to a domain using a single php script.
For example:
www.domain.com/something.php -> would be loading -> www.domain.com/process.php?u=something.php
www.domain.com/anything -> would be loading -> www.domain.com/process.php?u=anything
www.domain.com/su开发者_开发知识库b/dir/x -> would be loading -> www.domain.com/process.php?u=sub/dir/x
But process.php should never open directly on the browser, I want to do like an internal redirection.
Could someone show me how could I use htaccess and mod_rewrite to do this?
Put these lines into your .htaccess
file:
RewriteEngine On
RewriteRule (.*) process.php?u=$1 [QSA,L]
This will tell Apache to use process.php
instead of the actually requested page.
Most likely you will also need to add these lines before RewriteRule
line to tell Apache to process existing files as is, otherwise your images/css/javascript files will also be processed by process.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
精彩评论