简体   繁体   English

自动URL重写

[英]Automatic URL Rewriting

I have created .htaccess file. 我已经创建了.htaccess文件。

The original URL is: 原始网址是:

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

Redirected : 已重定向:

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

Redirecting works correctly.But,Now the problem is , 重定向可以正常工作。但是,现在的问题是,

it will be redirected only if i give the rewrited URL manually. 仅当我手动提供重写的URL时,它才会被重定向。 But it should do automatically only. 但是它应该只能自动执行。

my requirement is if anybody type "page.php?page=1&ipp=All&link=view-link" then automatic convert /page/1/All/link.html 我的要求是,如果有人输入“ page.php?page = 1&ipp = All&link = view-link”,则自动转换/page/1/All/link.html

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. 我仍然不清楚您要根据自己的问题提出什么,但是我会在暗中进行尝试,并假设您想将用户从那些“难看的” URL重定向到更干净的格式。 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]

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. 这将重定向到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 ,无论原始URL的任何组成部分是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM