自定义URL / Apache网址重写 [英] Custom URL / Apache URL Rewriting

查看:177
本文介绍了自定义URL / Apache网址重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让我的正则表达式正常工作。

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

这工作得很好:

重写规则^资料/([0-9] +)/ $ profile.php?customURL = $ 1 [NC,L]

但是,有一些错误。其一, $ 1 是字母数字,不只是数字(它仍然有效,虽然)。另外,我不希望简介/ 在URL中了。

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.

我试过这样:

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

但它并没有在所有的工作。我在做什么错了?

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

推荐答案

它看起来像你试图嵌入在另一个正则表达式?我不认为工作。试试这个:

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]

我们选择从字符串到最后,任选被终止的开始1个或多个单词字符的 /

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

这篇关于自定义URL / Apache网址重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆