1

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:

  • Old URL (URL#1): index.php?lang=AAA&zone=BBB&city=CCC&str=DDD&search=EEE
  • New URL (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

  • what I am trying to achieve is redirecting all visitors from (old) dynamic URL#1 to (new) dynamic URL#11

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

  • New URL (URL#11): index.php?lang=AAA&country=BBB&place=CCC&street=DDD
  • Sef URL (URL#2): /AAA/BBB/CCC/DDD

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!

4

3 回答 3

1

http://example.com/index.php?lang=AAA&zone=BBB&city=CCC&str=DDD&search=EEE

重定向到:

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

默默地映射到:

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

您可以在根目录中的一个 .htacces 文件中尝试此操作:

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]。

于 2013-03-26T06:34:12.970 回答
0

这是来自faa的有效代码(第一步):

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} lang=([^&]+)&zone=([^&]+)&city=([^&]+)&str=([^&]+)&search=  [NC]
RewriteRule .* /index.php?lang=%1&country=%2&place=%3&street=%4 [L,NC]
于 2013-03-26T16:35:57.903 回答
0

假设你的变量只包含小写字母和数字,试试这个:

RewriteRule ^/([a-z0-9]+)/([a-z0-9]+)/([a-z0-9]+)/([a-z0-9]+)$
    /index.php?lang=$1&country=$2&place=$3&street=$4
RewriteCond %{QUERY_STRING}
    ^lang=([a-z0-9]+)&zone=([a-z0-9]+)&city=([a-z0-9]+)&str=([a-z0-9]+)&search=[a-z0-9]+$
RewriteRule ^index.php$
    /index.php?lang=%1&country=%2&place=%3&street=%4 [R=permanent]

(请注意,必须没有换行符,但我已将它们插入此处并带有缩进,只是为了使该块在此网页上可读。)

于 2013-03-25T19:17:40.003 回答