htaccess RewriteRule results in “Object not found!”

无人久伴 提交于 2019-12-02 12:51:27

问题


My actual URL is <a href="<?php echo siteUrl;?>view.php?name=<?php echo $slug_url?>"><?php echo $heroheading ?></a>

Output

<a href="http://example.com/view.php?name=search-result">Click me</a>

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

and I added in the HTML <a href="<?php echo siteUrl;?>admin/service/<?php echo $slug_url?>"><?php echo $heroheading ?></a>

I tried below code in .htaccess but I am getting "Object not found!"

RewriteRule ^/?admin/service/([0-9\w]+)$ /view.php?name=$1

I checked on google and I tried same code but don't know why it's not working.

Would you help me out?


回答1:


You're close. Just change your rule to this:

RewriteRule ^/?admin/service/([\w-]+)/?$ view.php?name=$1 [L,QSA,NC]

\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.



来源:https://stackoverflow.com/questions/57787382/htaccess-rewriterule-results-in-object-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!