开发者

with and without trailing slash

What would I make this rule so that you can access it with and withou开发者_开发百科t trailing slash?

RewriteRule ^members/([^/]+)$ members.php?id=$1 [L]


RewriteRule ^members/([^/]+)/?$ members.php?id=$1 [L]

Just added "/?" at the end to say look for a trailing slash but the ? says it doesn't have to be there.


I don't know anything about this "mod-rewrite" you speak of (probably an Apache module?), but that sure looks like a regex, and I know about those. :-)

Try this:

RewriteRule ^members/([^/]+)(/|)$ members.php?id=$1 [L]

So, to break that into pieces, the ^ means "begins with", "members/" means matching exactly that, ([^/]+) means "1 or more characters that aren't slash, assigning to $1", (/|) means "slash or empty string, assigning to $2", and the $ part at the end means "the string has to end here".


I just needed to extract the domain name, so I used this:

^(?:https?:\/\/)?(?:www[0-9]*\.)?(.*?)(?:\/.*)?$

In my spreadsheet, it looks like this:

=REGEXEXTRACT(CELL_WITH_URL,"^(?:https?:\/\/)?(?:www[0-9]*\.)?(.*?)(?:\/.*)?$")

Hope that saves someone some time! Happy REGEXing!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜