htaccess的MOD改写$ _ GET变量用斜杠 [英] htaccess mod rewrite $_GET to variables with slashes
问题描述
我想重写网址与htaccess的,以便更好地可读的URL,并在PHP中使用维基,$ _ GET变量 我有时会使用一个子域,所以它有和没有工作。同样是变量没有必要在URL中。我拿最多3个变量在URL
I would like to rewrite URL's with htaccess to better readable URL's and use the $_GET variable in PHP
I sometimes make use of a subdomain so it has to work with and without. Also are the variables not necessary in the url. I take a maximum of 3 variables in the URL
网址 sub.mydomain.com/page/a/1/b/2/c/3
应引起 sub.mydomain。 COM / page.php A = 1安培; B = 2和C = 3
和网址 sub.mydomain.com/a/1/b/2/c/3
应引起 sub.mydomain.com/index.php?a=1&b=2&c=3
,其中 $ _ GET ['一'] = 1
the URL sub.mydomain.com/page/a/1/b/2/c/3
should lead to sub.mydomain.com/page.php?a=1&b=2&c=3
and the url sub.mydomain.com/a/1/b/2/c/3
should lead to sub.mydomain.com/index.php?a=1&b=2&c=3
where $_GET['a'] = 1
我想出了这个搜索和尝试了很多之后,
I came up with this after searching and trying a lot
RewriteEngine on
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4&$5=$6&$7=$8 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3&$4=$5&$6=$7 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4&$5=$6 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3&$4=$5 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)$ $1.domain.com/$2.php [L,QSA,NC]
但我得到的是一个未找到服务器错误
but what I get is an not found server error
我不是在这说好听的话,也许我负责的东西。
此外,我想它在结尾处并没有斜线工作
I'm not that good at this so maybe I oversee something.
Also I would like it to work with and without a slash at the end
我应该使用的RewriteCond和/或设置一些选项?
Should I make use of RewriteCond and/or set some options?
在此先感谢。
推荐答案
在使用重写规则
,不包括在该行的域名。另外,确保你在RewriteEngine叙述先处理。像这样的:
When using RewriteRule
, you don't include the domain name in the line. Also, make sure you turn on the RewriteEngine first. Like this:
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$ index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?$1=$2&$3=$4
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?$1=$2&$3=$4&$5=$6
第一行会重写 sub.mydomain.com/a/1
到 sub.mydomain.com/page.php?a=1
,第二次重写 sub.mydomain.com/a/1/b/2
到 sub.mydomain.com/ page.php一个= 1和; B = 2
,系统等
The first line will rewrite sub.mydomain.com/a/1
to sub.mydomain.com/page.php?a=1
, the second rewrites sub.mydomain.com/a/1/b/2
to sub.mydomain.com/page.php?a=1&b=2
, and so on.
这篇关于htaccess的MOD改写$ _ GET变量用斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!