htaccess RewriteRule导致“找不到对象!"; [英] htaccess RewriteRule results in "Object not found!"
问题描述
我的实际网址是<a href="<?php echo siteUrl;?>view.php?name=<?php echo $slug_url?>"><?php echo $heroheading ?></a>
输出
<a href="http://example.com/view.php?name=search-result">Click me</a>
我正在做的是,我必须重写URL.我想显示类似
What I am doing is, I have to rewrite the URL. I want to display the URL like
http://example.com/admin/service/search-result
并且我在HTML <a href="<?php echo siteUrl;?>admin/service/<?php echo $slug_url?>"><?php echo $heroheading ?></a>
我尝试使用.htaccess中的以下代码,但收到找不到对象!"
I tried below code in .htaccess but I am getting "Object not found!"
RewriteRule ^/?admin/service/([0-9\w]+)$ /view.php?name=$1
我在Google上进行了检查,并尝试了相同的代码,但不知道为什么它不起作用.
I checked on google and I tried same code but don't know why it's not working.
你能帮我吗?
推荐答案
您已经关闭.只需将规则更改为此:
You're close. Just change your rule to this:
RewriteRule ^/?admin/service/([\w-]+)/?$ view.php?name=$1 [L,QSA,NC]
\w
等同于[a-zA-Z0-9-]
,因此不需要单独0-9
.同样,您将需要字符类中的-
来匹配search-result
中的-
.
\w
is equivalent of [a-zA-Z0-9-]
so 0-9
is not required separately. Also you will need -
in character class to match -
in search-result
.
这篇关于htaccess RewriteRule导致“找不到对象!";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!