htaccess RewriteRule 导致“找不到对象!"; [英] htaccess RewriteRule results in "Object not found!"
问题描述
我的实际 URL 是 <a href="<?php echo siteUrl;?>view.php?name=<?php echo $slug_url?>"><?php echo$heroheading ?></a>
My actual URL is <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-9w]+)$ /view.php?name=$1
我在谷歌上查了一下,我尝试了相同的代码,但不知道为什么它不起作用.
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屋!