当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - Using Special Character (-) in .htaccess file with PHP

问题描述:

I am trying to write a rewrite rule in .htaccess. It has been working fine till now. But today, I tried to write a rule and I have special character (-) in the variable. Something like this

http://127.0.0.1/website/client/ticket/update/KU0-QMV-882Q/

KU0-QMV-882Q is the Variable.

My rewrite rule is as follows

# This Directive will make Apache look first

Options +FollowSymLinks

RewriteEngine on

RewriteRule ^orders/pending$ orders.php?type=pending

RewriteRule ^orders/completed$ orders.php?type=completed

RewriteRule ^logout$ logout.php

RewriteRule ^login$ login.php

RewriteRule ^ticket/open$ open-ticket.php

RewriteRule ^order/view/(\w+)$ show-order-details.php?id=$1

RewriteRule ^ticket/update/(\w+)$ update-ticket.php?ticket_no=$1

Now when I try to access the URL it gives a 404 NOt Found Error.

So what do I need to write in the .htaccess file?

Thanks in advance for your help.

Regards,

Pratik G

网友答案:

In your rule \w+ means every letters, digits and underscore but not hyphen. You should use [\w-]+ instead.

分享给朋友:
您可能感兴趣的文章:
随机阅读: