本文介绍了使用.hataccess重写动态url结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将动态URL(如下)重写为稍有不同的结构;要么不起作用,要么我不确定是否正确:

I've tried to rewrite the dynamic URL (below) to a slightly different structure; either does not work or I am not sure if it is correct:

  • 旧网址(URL#1):index.php?lang = AAA& zone = BBB& city = CCC& str = DDD& search = EEE
  • 新网址(URL#11):index.php?lang = AAA& country = BBB& place = CCC& street = DDD

*基本上更改了名称,搜索"字符串不再重要

*basically changed the names and the "search" string is not important any more

  • 我要实现的目标是将所有访问者从(旧)动态URL#1重定向到(新)动态URL#11

第二步,在所有搜索引擎都显示了新的网址并完成了使用非自定义网址更容易的所有测试之后,我们希望将URL#11重写为URL#2

In a second step, after all search engines show the new urls and we finished all test that are easier with non-sef urls, we would like to rewrite URL#11 to URL#2

  • 新网址(URL#11):index.php?lang = AAA& country = BBB& place = CCC& street = DDD
  • 自URL(URL#2):/AAA/BBB/CCC/DDD

我对apache编程不是很熟悉,即使我的解决方案能够正常工作,我们也不确定它是否正确,或者不确定某些URL是否会产生错误.对于创建用于进行SEF网址的第1步重定向的.htaccess文件和以后要使用的单独的.htaccess文件,任何帮助将不胜感激.谢谢!

I am not very familiar with apache programming and even when my solution works, we are not sure if it is the right one or if it will generate errors with certain URLs. Any help would be highly appreciated in creating a .htaccess file that does the step 1 redirection and a separate .htaccess file to be used later, for SEF urls. THANK YOU!

推荐答案

重定向到:

http://example.com/AAA/BBB/CCC/DDD

静默映射到:

http://example.com/index.php?lang=AAA&country=BBB&place=CCC&street=DDD

您可以在根目录下的一个.htacces文件中进行尝试:

You may try this in one .htacces file in root directory:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} lang=([^&]+)&zone=([^&]+)&city=([^&]+)&str=([^&]+)&search=  [NC]
RewriteRule .* /%1/%2/%3/%4?   [R=301,L,NC]

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?  [NC]
RewriteCond %{REQUEST_URI} !index\.php                          [NC]
RewriteRule .* /index.php?lang=%1&country=%2&place=%3&street=%4 [L,NC]

如果查询包含以下格式的参数:%nn,请尝试在两个规则中添加 B 标志.例如:[L,NC,B].

If the query contains parameters in this format: %nn, try adding the B flag to both rules. Example: [L,NC,B].

这篇关于使用.hataccess重写动态url结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 19:08