Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess URL重写的正则表达式_Php_.htaccess - Fatal编程技术网

Php htaccess URL重写的正则表达式

Php htaccess URL重写的正则表达式,php,.htaccess,Php,.htaccess,嗨 我想重写目录www.mysite.com/index.php?category=news 访问www.mysite.com/news 我写了这段代码,但它不起作用 任何人都可以帮忙 谢谢你的帮助 RewriteEngine On RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?category=$1 感谢所有回答我问题的人,当我尝试写www.mysite.com/news时,所有代码都是有效的,但我的意思是当我点击链接时 “a href='ind

我想重写目录www.mysite.com/index.php?category=news 访问www.mysite.com/news 我写了这段代码,但它不起作用 任何人都可以帮忙 谢谢你的帮助

RewriteEngine On    
RewriteRule  ^([a-zA-Z0-9-/]+)$ index.php?category=$1
感谢所有回答我问题的人,当我尝试写www.mysite.com/news时,所有代码都是有效的,但我的意思是当我点击链接时 “a href='index.php?category=news'”link“/a”我想立即被重写到www.mysite.com/news

这样行吗

RewriteBase /
RewriteRule (.*) index.php?category=$1 [QSA,NC,L]

只是确认一下,您要匹配的模式都是字母、数字、连字符和正斜杠,对吗

如果是,试试这个

RewriteRule ^([a-zA-Z0-9/-]+)$ index.php?category=$1 [QSA,L]
我认为问题可能在于字符类表达式中连字符和正斜杠的顺序。要匹配连字符,它们应该出现在字符集中的第一个或最后一个。

试试这个

Options +FollowSymLinks
RewriteEngine on
RewriteRule news/ index.php?category=news
RewriteRule news index.php?category=news

当你去的时候会发生什么?我很确定你的意思是“把
news
重写到
index.php?category=news
”而不是反过来Levi Morrison,它很管用,但我的意思是当我点击一个链接“a href='index.php?category=news'”链接/a“我想立刻被重写到www.mysite.com/news”
RewriteRule ^(news|or|some|other|category)$ index.php?category=$1 [QSA,NC,L]