0

我想在使用 mod_rewrite 时通过 url 传递数据。我在 stackoverflow 和其他网站上阅读了许多链接,但找不到解决方案。

结果网址为:

http://example.com/Path/logmanagement/view/1/?name=3&type=klik

print_r 返回: Array ( [action] => logbeheer [do] => view [id] => 1 )

目前我有这个htaccess:

Options -Indexes

ServerSignature Off

RewriteEngine On

#RewriteBase /

##this part is what I tried##

RewriteCond %{QUERY_STRING} ^name=(\d+)&type=(\w+)$
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)$ index.php?action=$1&do=$2&id=$3&name=%1&type=%2
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3&name=%1&type=%2

##end this part##

# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<script>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule ^.*$ - [F,L] 
# END Filtering

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z_0-9-]+)$ index.php?action=$1
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)$ index.php?action=$1&do=$2
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)$ index.php?action=$1&do=$2&id=$3
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)$ index.php?action=$1&do=$2&id=$3&id2=$4



RewriteRule ^([a-zA-Z_0-9-]+)/$ index.php?action=$1
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/$ index.php?action=$1&do=$2
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3&id2=$4

RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3&name=%1&type=%2

# Fixed upload issues for the milti file upload

SetEnvIfNoCase Content-Type "^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
4

1 回答 1

2

我想通过 URL(名称和类型)传递 2 个表单字段以将其读取为 GET。

然后您应该将 QSA 标志添加到所需的 mor_rewrite 规则。

RewriteRule ^(.*)/(.*)/$ /somefile.php?var1=$1&var2=$2 [QSA]

http://example.com/abc/def/?a=10&b=hello

print_r($_GET);
Array(
    var1 = 'abc'
    var2 = 'def'
    a = '10'
    b = 'hello'
);

希望,这就是你要找的。

于 2013-03-22T10:15:40.107 回答