我正在尝试将用户键入的所有 URL 登录到数据库。
在此之后,如果路径存在,我想将用户重定向到路径
否则我想将用户留在根目录中。
我输入的网址 http://www.mydomain.com/folder1/index.php
输出画面
folder1/index.php
Array ( [0] => folder1 [1] => index.php ) url = to folder 1
folder1/index.php
根目录 index.php
<?php
if ($_GET['url']!= "") {
// url not empty there is query string
$url = $_GET['url'];
$url = rtrim($url, '/');
echo ($url.'<br />');
$url = explode('/', $url);
$file = $url[0];
print_r($url);
}
else // url empty it is root directory
{echo ('<br /> url empty <br />');}
if ($url[0] == 'folder1'){
echo ('url = to folder 1<br />');
$path = $url[0].'/index.php';
//the path exists do redirect to folder1/index.php
echo $path ;
header( 'Location: http://www.mydomain.com/{$path}' ) ;
}
?>
Htaccess
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.mydomain\.com
RewriteRule (.*) //www.mydomain.com/$1 [R=301,L]
RewriteRule \.(sql)$ - [F]
RewriteRule \.(txt)$ - [F]
RewriteRule \.(zip)$ - [F]
RewriteRule \.(rar)$ - [F]
<IfModule mod_rewrite.c>
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
Options -Indexes
RewriteEngine On
RewriteCond %{http_host} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]
RewriteRule ^([^\.]+)$ index.php?url=$1 [QSA,L,NE]
</IfModule>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,NE]
非常感谢