I want to use Apache rewrite to implement a single entry in php and redirect all requests to the index. php, and then analyze $ _ SERVER [& #039; REQUEST_URI & #039;] to build the routing function. A problem occurs during use. Other addresses are requested, such as localhost... I want to use Apache rewrite to implement a single entry in php and redirect all requests to the index. php, and then analyze $ _ SERVER ['request _ URI '] to build the routing function.
A problem occurs during use. You can obtain the result by requesting other addresses, such as http: // localhost/a/B/c.
array (size=4) 0 => string '' (length=0) 1 => string 'a' (length=1) 2 => string 'b' (length=1) 3 => string 'c' (length=1)
However, if it is http: // localhost/index, the Error 404 is returned. Why?
This is probably the case with index. php.
The virtualhost configuration is as follows:This rewrite rule is found online
DocumentRoot/home/www
Options FollowSymLinksAllowOverride None # AllowOverride All
RewriteEngine onRewriteBase/# index. phpRewriteCond % {REQUEST_FILENAME} is not displayed }! -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. php index.html index.htm
Reply content:I want to use Apache rewrite to implement a single entry in php and redirect all requests to the index. php, and then analyze $ _ SERVER ['request _ URI '] to build the routing function.
A problem occurs during use. You can obtain the result by requesting other addresses, such as http: // localhost/a/B/c.
array (size=4) 0 => string '' (length=0) 1 => string 'a' (length=1) 2 => string 'b' (length=1) 3 => string 'c' (length=1)
However, if it is http: // localhost/index, the Error 404 is returned. Why?
This is probably the case with index. php.
The virtualhost configuration is as follows:This rewrite rule is found online
DocumentRoot/home/www
Options FollowSymLinksAllowOverride None # AllowOverride All
RewriteEngine onRewriteBase/# index. phpRewriteCond % {REQUEST_FILENAME} is not displayed }! -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. php index.html index.htm
Your rule has a problem.
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
It won't work. The correct one should beRewriteRule ^(.*)$ index.php?$1 [QSA,PT,L]
.?
That's it.$1
To index. php, and/
Tell apache to searchindex.php/
The index file under the directory is 404.
You can add the following configuration to httpd. conf, debug mod_rewrite, and view rewrite. the log file can know what the path obtained through rewrite is. After debugging is completed, remove the configuration. Otherwise, performance and security may be affected.
# Output debugging information to rewrite. log
RewriteLog "/var/log/apache2/rewrite. log" RewriteLogLevel 3
Http://httpd.apache.org/docs/2.2/mod...
In addition, there is no need to write the rewrite rule in httpd. conf. It is better to use. htaccess.
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} is not displayed }! -D RewriteCond % {REQUEST_FILENAME }! -F RewriteRule ^ (. *) $ index. php? $1 [QSA, PT, L]
RewriteCond %{SCRIPT_FILENAME} !-fRewriteCond %{SCRIPT_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1