I want to use Apache rewrite to implement a single portal in PHP, redirect all requests to index.php, and then analyze $_server[' Request_uri '] to build the routing function.
At the time of use there is a problem, request other addresses, such as http://localhost/a/b/c can get results
Array (size=4) 0 = String ' (length=0) 1 = = String ' A ' (length=1) 2 = string ' B ' (length=1) 3 = = String ' C ' (length=1)
But if it's http://localhost/index, you'll be prompted with a 404 error, which is why.
Index.php, that's probably it.
VirtualHost configuration is like this
This rewrite rule was found on the Internet.
Documentroot/home/www
Options followsymlinksallowoverride none#allowoverride
All Rewriteengine onrewritebase/#不显示index. Phprewritecond%{request_filename}!-drewritecond%{request_filename}!- Frewriterule ^ (. *) $ index.php/$1 [qsa,pt,l] #RewriteRule ^ (. *) $ index.php?$1 [qsa,l]
Options Indexes followsymlinks multiviewsallowoverride none#allowoverride all Order allow,denyallow from Alldirectoryindex index.php index.html index.htm
Reply content:
I want to use Apache rewrite to implement a single portal in PHP, redirect all requests to index.php, and then analyze $_server[' Request_uri '] to build the routing function.
At the time of use there is a problem, request other addresses, such as http://localhost/a/b/c can get results
Array (size=4) 0 = String ' (length=0) 1 = = String ' A ' (length=1) 2 = string ' B ' (length=1) 3 = String ' C ' (length=1)
But if it's http://localhost/index, you'll be prompted with a 404 error, which is why.
Index.php, that's probably it.
VirtualHost configuration is like this
This rewrite rule was found on the Internet.
Documentroot/home/www
Options followsymlinksallowoverride none#allowoverride
All Rewriteengine onrewritebase/#不显示index. Phprewritecond%{request_filename}!-drewritecond%{request_filename}!- Frewriterule ^ (. *) $ index.php/$1 [qsa,pt,l] #RewriteRule ^ (. *) $ index.php?$1 [qsa,l]
Options Indexes followsymlinks multiviewsallowoverride none#allowoverride all Order allow,denyallow from Alldirectoryindex index.php index.html index.htm
There's something wrong with your rules.
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
The right thing to do is RewriteRule ^(.*)$ index.php?$1 [QSA,PT,L]
. ?
It's going to go back to the $1
index.php, and /
tell Apache to find index.php/
the index file under the directory, which is naturally 404.
You can add the following configuration to httpd.conf, Debug mod_rewrite, by looking at the Rewrite.log file can know what the path through rewrite, and remove this configuration after debugging, otherwise there will be some performance security impact.
# output debug information to Rewrite.log
rewritelog "/var/log/apache2/rewrite.log" rewriteloglevel 3
Http://httpd.apache.org/docs/2.2/mod/...
In addition, rewrite rules do not necessarily write httpd.conf inside, use. htaccess better.
httpd.conf
Documentroot/home/www
Options followsymlinks allowoverride None #AllowOverride
All
Options Indexes followsymlinks multiviews allowoverride None #AllowOverride all Order Allow,deny allow from all directoryindex index.php index.html index.htm
/home/www/.htaccess
Rewriteengine on #不显示index. PHP rewritebase/ rewritecond%{request_filename}!-d Rewritecond%{ Request_filename}!-f rewriterule ^ (. *) $ index.php?$1 [qsa,pt,l]
Rewritecond%{script_filename}!-frewritecond%{script_filename}!-drewriterule ^ (. *) $ index.php/$1