0

我有这样的可怕网址:

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 page not found 错误!

4

2 回答 2

1

您不想在重写的网址中包含“子文件夹”吗?

RewriteRule ^subfolder/index.php /subfolder/menu/$1/$2/#? [R=301,L]

于 2012-04-29T01:41:29.177 回答
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

更新 2(因为没有子文件夹 - 见评论):

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

请阅读本网站: http ://corz.org/serv/tricks/htaccess2.php

于 2012-04-29T01:52:03.807 回答