.htaccess mod_rewrite...我想?

发布于 2025-01-05 16:42:11 字数 367 浏览 3 评论 0原文

我想知道如何在 .htaccess 中重定向以下 URL:

/mysite.com/blog/Something => /mysite.com/blog.php?tag=某事

这是我在另一个网站上使用过的脚本,但这有点简单:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?name=$1
</IfModule>

提前致谢

I was wondering how in .htaccess I can redirect the following URL:

/mysite.com/blog/Something => /mysite.com/blog.php?tag=Something

Here is a script I've used on a different site however this is a bit simpilar:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?name=$1
</IfModule>

Thanks in Advance

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

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

发布评论

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

评论(2

羅雙樹 2025-01-12 16:42:11

只需添加此规则:

RewriteRule ^blog/(.*)$ blog.php?tag=$1 [L,QSA,NC]

更新:根据您的评论,这是您需要的规则:

RewriteRule ^blog/([^/]*) blog.php?tag=$1 [L,QSA,NC]

Just add this rule:

RewriteRule ^blog/(.*)$ blog.php?tag=$1 [L,QSA,NC]

Update: As per your comment this is the rule you will need:

RewriteRule ^blog/([^/]*) blog.php?tag=$1 [L,QSA,NC]
诠释孤独 2025-01-12 16:42:11

尝试将以下内容添加到站点根目录中的 .htaccess 文件中。

RewriteEngine on
RewriteBase / 

#/mysite.com/blog/Something to /mysite.com/blog.php?tag=Something
RewriteRule ^blog/(something)$ blog.php?tag=$1 [L,NC,R=301] 

如果 something 是变量,则将规则更改为“

RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC,R=301] 

如果您希望 URL 在用户浏览器中保持不变,则删除 R=301”,如下所示

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

Try adding the following to the .htaccess file in the root directory of your site.

RewriteEngine on
RewriteBase / 

#/mysite.com/blog/Something to /mysite.com/blog.php?tag=Something
RewriteRule ^blog/(something)$ blog.php?tag=$1 [L,NC,R=301] 

If something is a variable then change the rule to

RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC,R=301] 

If you want the URL to stay the same in the Users browser then drop the R=301 as below

RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文