Mod Rewrite创建一个简短的直接链接(Mod Rewrite to create a short direct link)

编程入门 行业动态 更新时间:2024-10-09 05:12:39
Mod Rewrite创建一个简短的直接链接(Mod Rewrite to create a short direct link)

目前在我的网站上,访问者可以通过访问“www.mywebsite.com/index.php?post=123”直接访问不同的帖子,其中123是帖子编号。

我试图使用htaccess稍微清理直接链接,所需的结果是用户可以访问“www.mywebsite.com/123”并且htaccess会将它们带到“www.mywebsite.com/index.php” ?交= 123。

我尝试使用以下Modrewrite,但它指示我遇到404错误:

RewriteRule ^/([0-9]+)$ /index.php?videoID=$1 [QSA]

我确信Modrewrite模块正在运行,因为我正在使用其他规则。 这是我的整个.htaccess文件:

RewriteEngine On RewriteRule ^/([0-9]+)$ /index.php?videoID=$1 [QSA] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Currently on my website visitors can directly access different posts by going to "www.mywebsite.com/index.php?post=123", where 123 is the post number.

I am trying to use htaccess to clean up the direct link up slightly, the desired result is that the user can go to "www.mywebsite.com/123" and htaccess will take them to "www.mywebsite.com/index.php?post=123.

I have tried using the following Modrewrite but it is directing me to a 404 error:

RewriteRule ^/([0-9]+)$ /index.php?videoID=$1 [QSA]

I am sure that the Modrewrite module is working because I am using other rules aswell. Here is my entire .htaccess file:

RewriteEngine On RewriteRule ^/([0-9]+)$ /index.php?videoID=$1 [QSA] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

最满意答案

如果这些规则在.htaccess文件中,则需要从用于匹配URI的正则表达式中删除前缀(前导斜杠):

RewriteRule ^([0-9]+)$ /index.php?videoID=$1 [QSA]

If these rules are in your .htaccess file, you need to remove the prefix (the leading slash) from the regular expression used to match against the URI:

RewriteRule ^([0-9]+)$ /index.php?videoID=$1 [QSA]

更多推荐

本文发布于:2023-04-29 09:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335602.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简短   创建一个   链接   Rewrite   Mod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!