使用 Mod Rewrite 以句点结尾

发布于 2024-08-15 12:32:01 字数 635 浏览 9 评论 0原文

我想知道如何在我的网址末尾添加句点。目前,如果我有网址:

http://www.mydomain.com/Page/IDK

抓取信息的页面将返回

标题:IDK(没有结束句点)

其他标点符号也会发生这种情况,并且它会影响我的页面错误地显示信息。感谢您的浏览,希望有人知道解决方案。

我在 htaccess 文件中使用以下内容:

RewriteRule ^([^/.]+)/?$ /index.php?Page=$1 [L]
RewriteRule ^([^/.]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2&Level2=$3 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2&Level2=$3&Level3=$4 [L]

I would like to know how to allow periods at the end on my url's. Currently if I had the url:

http://www.mydomain.com/Page/I.D.K.

The page grabbing the information would return

Title: I.D.K (Without the ending period)

This also happens with other punctuation and it is effecting my pages displaying information wrongly. Thanks for looking, hope somebody knows the solution.

I am using the following in my htaccess file:

RewriteRule ^([^/.]+)/?$ /index.php?Page=$1 [L]
RewriteRule ^([^/.]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2&Level2=$3 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2&Level2=$3&Level3=$4 [L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路还长,别太狂 2024-08-22 12:32:01

好吧,问题基本上解决了。如果我尝试执行 Artist1 & 操作,& 仍然会破坏我的琴弦。 Artist2 但我只会使用字符串替换来用其他东西替换该符号。无论如何,为了允许在任何地方使用标点符号,即使在最后,我在重写规则中将所有 + 替换为 * 。现在看起来是这样的:

RewriteRule ^([^/.]*)/?$ /index.php?Page=$1 [L]
RewriteRule ^([^/.]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2 [L]
RewriteRule ^([^/.]*)/([^/]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2&Level2=$3 [L]
RewriteRule ^([^/.]*)/([^/]*)/([^/]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2&Level2=$3&Level3=$4 [L]

希望这可以帮助其他有类似问题的人。

Ok problem virtually solved. The & still breaks my strings if I try doing Artist1 & Artist2 but I will just use string replace to replace that symbol with something else. Anyway, to allow punctuation anywhere, even at the end, I replaced all + with * in my rewrite rules. Here is how it looks now:

RewriteRule ^([^/.]*)/?$ /index.php?Page=$1 [L]
RewriteRule ^([^/.]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2 [L]
RewriteRule ^([^/.]*)/([^/]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2&Level2=$3 [L]
RewriteRule ^([^/.]*)/([^/]*)/([^/]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2&Level2=$3&Level3=$4 [L]

Hope this helps some other people with similar problems.

暮光沉寂 2024-08-22 12:32:01

我假设它位于 http://www.mydomain.com/ 中。这是我用于第二条规则的内容(然后可以将其转换为其他规则):

RewriteRule ^([A-Za-z0-9\-,]+)/([A-Za-z0-9.\-,]+)/?$ /index.php?Page=$1&Level1=$2 [L]

它将匹配以下内容:(并允许使用连字符、逗号和 Level1 的句点)

IDK/Jump.ing.
IDK/Jump.ing./

但不会:

S$!LV/J

我尝试将我的规则列入白名单选项(例如 /[AZ]/),而不是将它们列入黑名单(/[^3-5]/)。我确信这两个选项都有争议,但我最喜欢白名单,因为我可以控制可以使用的内容。如果我不将其包含在我的列表中,那么它就不是一个有效的选项。当然,如果您接受很多选项,那么这可能会导致一些非常长的字符类或诸如此类的情况。如果有人访问 http://www.mydomain.com/Page/IDK&somevariable 该怎么办=某个值?它可能会破坏你的脚本(如果这个人很聪明)。您的 RewriteRule 会将它们发送到 /index.php?Page=Page&Level1=IDK&somevariable=somevalue。完全不是你预期会发生的事情。

I'm assuming this is located in http://www.mydomain.com/. Here's what I'd use for the second Rule (which can then be transposed to the other rules):

RewriteRule ^([A-Za-z0-9\-,]+)/([A-Za-z0-9.\-,]+)/?$ /index.php?Page=$1&Level1=$2 [L]

That will match the following: (and will allow for hyphens, commas, and periods for Level1)

IDK/Jump.ing.
IDK/Jump.ing./

But not:

S$!LV/J

I try and whitelist my options (something like /[A-Z]/), rather than blacklist them (/[^3-5]/). I'm sure there are arguments for both options, but I like whitelisting mostly because I have control over what can be used. If I don't include it in my list, it's not a valid option. Of course, if you're accepting a LOT of options, then this could make for some very long character classes or whatnot. What if someone went to http://www.mydomain.com/Page/I.D.K.&somevariable=somevalue ? It could potentially break your script (if the person is smart). Your RewriteRule would send them to /index.php?Page=Page&Level1=I.D.K.&somevariable=somevalue. Not at all what you anticipated happening.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文