htaccess重写或php url爆炸
我正在尝试创建自己的MVC。我真的在试图操纵url。我试图得到几个参数,以形成一个完整的网址。 我想转身htaccess重写或php url爆炸,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正在尝试创建自己的MVC。我真的在试图操纵url。我试图得到几个参数,以形成一个完整的网址。 我想转身 http://example.com/?action=account&user=JohnDoe 到 但我似乎无法使.htaccess文件正常工作:/ 这就是我所拥有的 Options +FollowSymLinks RewriteEngine On RewriteRule ^([a-zA-Z0-9-=_?]+)/?$ index.php?action=$1&user=$2
http://example.com/?action=account&user=JohnDoe
到
但我似乎无法使.htaccess文件正常工作:/
这就是我所拥有的
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-=_?]+)/?$ index.php?action=$1&user=$2 [NC,L]
当我转到
http://example.com/account/JohnDoe
我收到一个404错误。如果缺少一个参数,请尝试此操作
重写规则^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$index.php?action=$1&user=$2[NC,L]与其为特定URL设置一个mod_重写规则,为什么不建立一个完整的框架呢 修改如下:
#URI PATH CONSTRUCTION
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /index.php?string=$1 [L,QSA]
</IfModule>
这确实有效,但有没有办法让我可以转到
http://example.com/login
因为需要两个参数,所以不会出错?您可以为此创建一个新的重写规则谢谢!所有这些都起作用了,我最终在重写规则([accounts]+)/([A-Za-z0-9-]+)/?$index.php?action=$1&user=$2[NC,L]
重写规则([A-Za-z0-9-])/?$index.php?action=$1[L]
#URI PATH CONSTRUCTION
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /index.php?string=$1 [L,QSA]
</IfModule>
if (isset($_GET['string'])) {
//DEALS WITH GET PARAMETERS
if (strstr($_GET['string'],"?") !== false) {
$pos = 0;
$tailstr = substr($_GET['string'],$pos);
$endpos = strpos($tailstr, "?");
$endpos = $endpos + strlen("?");
$string = substr($_GET['string'],$pos,$endpos);
} else {
$string = $_GET['string'];
}
$path = explode("/",$_GET['string']);
}
//Depth to 5 levels
for ($i=0;$i<5;$i++) {
if (!isset($path[$i])) $path[$i] = null;
}
global $path;
$path[0] = 'account'
$path[1] = 'JohnDoe'
$path[2] = ''
$path[3] = ''
$path[4] = ''