0

我是 URL 重写的新手。

我在主页中有一个锚文本,单击时将打开另一个页面。单击链接时在浏览器中显示的目标 url 是 http://example.com/index.php?p=one/two/three/pdp&abc=436

相反,我想在 URL http://example.com/index.php?p=shopping/shop/ipad/pdp&abc=436中显示。

所以基本上我正在看的是从一/二/三替换URL

购物/购物/ipad

我希望 URL http://example.com/index.php?p=one/two/three/pdp&abc=436 看起来像http://example.com/index.php?p=shopping/shop/ipad/ pdp&abc=436

请注意,我有 14,000 页,因此无法在任何地方进行物理更改。我希望使用 url 重写来实现这一点。因此,在根目录中,我已将以下几行添加到 .htaccess 中。

RewriteEngine On  
RewriteRule  ^shopping/shop/ipad/?$ one/two/three/pdp [NC,L] 

但这是给内部服务器错误。

我怎样才能显示更好的网址?谢谢

4

4 回答 4

1

You may try this:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING}  p=one/two/three/(.*)
RewriteRule .*  http://example.com/index.php?p=shopping/shop/ipad/%1? [R=301,L]

It will redirect:

http://example.com/index.php?p=one/two/three/pdp&abc=436

To:

http://example.com/index.php?p=shopping/shop/ipad/pdp&abc=436

I am assuming `p=one/two/three/ and p=shopping/shop/ipad/ are constants. If they are variables you should update the question and describe their relationship and patterns, to be able to capture and substitute them.

SECOND OPTION:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING}  p=one/two/three/([^/]+)&([^/]+)=([^/]+).*
RewriteRule .*  http://example.com/index.php?p=shopping/shop/ipad/%1/%2/%3? [R=301,L]

It will redirect:

http://example.com/index.php?p=one/two/three/anything1&anything2=anything3

To:

http://example.com/index.php?p=shopping/shop/ipad/anything1/anything2/anything3

于 2012-12-28T16:38:39.053 回答
0

试试这个:

Redirect 301 old_url new_url

例子:

Redirect 301 index.php?p=one/two/three/pdp&abc=436 http://example.com/index.php?p=shopping/shop/ipad/pdp&abc=436

我希望你能解决你的问题,对不起,如果你不这样做,我还没有尝试过。

问候。

于 2012-12-28T15:51:14.083 回答
0
于 2012-12-28T16:03:11.527 回答
0

Yet another method:

If you have enough access to change the index.php script, you could do the rewrite there, and not in the web server. This has the advantage that you have a powerful language at your disposal, which already has good handling of query strings.

于 2012-12-28T16:06:16.160 回答