简体   繁体   中英

301 redirect from old to new URL without querystring and?

I'm trying to redirect from my old URL structure to a new one where in my case some parameters are added.

The old structure looked like www.url.com/detail/111.html which is rewritten from www.url.com?action=detail&id=111 Now the structure changed for SEO reasons, new the URL for the site mentioned above is something like www.url.com/detail/111/cat/sub.html.

Now i want to redirect from www.url.com/detail/111.html to www.url.com/detail/111/cat/xyz.html

or from www.url.com/detail/112.hmtl to www.url.com/detail/112/cat/abc.html

The last part in the new URLs is variable!

If im doing it with: Redirect 301 /detail/112.html http://www.url.com/detail/112.cat/abc.html the querystring ist added to the new url. The browser shows: http://www.url.com/detail/112.cat/abc.html?action=detail&id=112

When I'm adding a ? to the new URL the ? is also shown in the browser.

QSD doesn't work because Apache 2.2 is running.

Has anyone an idea what to do to solve the problem?

You can put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^detail/112\.html$ http://www.url.com/detail/112.cat/abc.htm? [L,NC,R]

Take note of ? at the end of target URL that is used to strip off any existing query string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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