我有这样可怕的网址:
http://example.com/subfolder/index.php?a=1&b=1&token=8d519decbe60db44154b1fbc8c553ac4
我试图让它看起来像这样:
http://example.com/subfolder/menu/1/1/#/
但是这段代码导致页面崩溃/找不到或者是什么:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^a=([0-9]+)&b=([0-9]+)&token=([A-Za-z0-9]+)
RewriteRule ^subfolder/index.php /menu/$1/$2/#? [R=301,L]
我将此.htaccess
文件放在我的根文件夹example.com/.htaccess
中,是否需要将其放在子文件夹中?
我找不到404页错误!
答案 0 :(得分:1)
您不想在重写的网址中包含“子文件夹”吗?
RewriteRule ^子文件夹/ index.php /子文件夹/ menu / $ 1 / $ 2 /#? [R = 301,L]
答案 1 :(得分:1)
尝试不同的方法:
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)/([0-9]+)/([0-9]+)/$ index.php?a=$1&b=$2&token=$3 [L,QSA]
输出:(http://example.com/subfolder/menu/1/1/#/)
<?php
print_r($_GET);
Array
(
[a] => menu
[b] => 1
[token] => 1
)
?>
或http://example.com/subfolder/menu/1/18d519decbe60db44154b1fbc8c553ac4/#/
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)/([0-9]+)/([A-Za-z0-9]+)/$ index.php?a=$1&b=$2&token=$3 [L,QSA]
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)/([0-9]+)/([0-9]+)/([A-Za-z0-9]+)/$ index.php?a=$2&b=$3&token=$4 [L,QSA]
将匹配:mysite.com/subfolder/menu/1/2/blah123
并传递给index.php?a=1&b=2&token=blah123
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)/([0-9]+)/([0-9]+)/([A-Za-z0-9]+)/$ index.php?a=$3&b=$4&token=$5 [L,QSA]
将匹配:mysite.com/subfolder/menu/1/2/blah123
并传递给index.php?a=1&b=2&token=blah123