Custom URL / Apache URL Rewriting

。_饼干妹妹 提交于 2019-12-11 21:12:27

问题


I can't seem to get my regex working properly.

This works fine:

RewriteRule ^profile/([0-9]+)/?$ profile.php?customURL=$1 [NC,L]

But there's some mistakes. For one, the $1 is alphanumeric, not just numbers (it still works, though). Also, I don't want profile/ in the URL anymore.

I tried this:

RewriteRule ^(/^\w+$/)/?$ profile.php?customURL=$1 [NC,L]

But it didn't work at all. What am I doing wrong?


回答1:


It looks like you're trying to embed a regex inside another? I don't think that works. Try this:

RewriteRule ^(\w+)/?$ profile.php?customURL=$1 [NC,L]

We select 1 or more word characters from the start of the string to the end, optionally terminated by a /.



来源:https://stackoverflow.com/questions/9689446/custom-url-apache-url-rewriting

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