自动 URL 重写 [英] Automatic URL Rewriting

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

问题描述

我已经创建了 .htaccess 文件.

I have created .htaccess file.

原始网址为:

http://example.com/folder/page.php?page=1&ipp=All&link=view_link

重定向:

http://example.com/folder/page/1/All/link.html

重定向工作正常.但是,现在问题是,

Redirecting works correctly.But,Now the problem is ,

只有当我手动提供重写的 URL 时,它才会被重定向.但它应该只自动执行.

it will be redirected only if i give the rewrited URL manually. But it should do automatically only.

我的要求是如果有人输入page.php?page=1&ipp=All&link=view-link"然后自动转换/page/1/All/link.html

推荐答案

根据你的问题,我仍然不清楚你想要什么,但我会在黑暗中试一试并假设你想重定向用户从那些丑陋"的 URL 到更简洁的格式.如果是这样,这应该可行.

I'm still very unclear on what you want based on your question, but I'll take a stab in the dark and assume you wanted to redirect the user from those "ugly" URLs to the cleaner format. If that's the case, this should work.

RewriteCond %{THE_REQUEST}  ^[A-Z]+\s/[^/]+/.*\.php
RewriteCond %{QUERY_STRING} page=([^&]+)
RewriteRule ^([^/]+/[^/]+)\.php /$1/%1 [C]
RewriteCond %{QUERY_STRING} ipp=([^&]+)
RewriteRule .* $0/%1 [C]
RewriteCond %{QUERY_STRING} link=view(_|-)([^&]+)
RewriteRule .* $0/%2.html? [R=301,L]

哪些用户会重定向到 folder/page.php?page=1&ipp=All&link=view-link(或者是 /folder/page.php?page=1&ipp=All&link=view_link?你的问题都有,所以我让它接受)到folder/page/1/All/link.html,不管该原始网址的任何组成部分是什么.

Which will redirect users who go to folder/page.php?page=1&ipp=All&link=view-link (Or is it /folder/page.php?page=1&ipp=All&link=view_link? Your question has both, so I let it accept either) to folder/page/1/All/link.html, regardless of what any of the components of that original URL are.

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

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