questionbank
questionbank

Reputation: 440

htaccess RewriteRule results in "Object not found!"

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?

Upvotes: 1

Views: 128

Answers (1)

anubhava
anubhava

Reputation: 785286

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.

Upvotes: 1

Related Questions