htaccess 301 redirect with query

你离开我真会死。 提交于 2020-01-25 00:32:26

问题


I'm trying to setup an htaccess redirect with query just like this:

Redirect 301 /?page=services/branddevelopment /brand-development?

or this:

RewriteCond   %{QUERY_STRING}   ^page=services/branddevelopment$
RewriteRule   ^(.*)$ http://domainname/   [R=301,L]

Am I missing something in here? Or a wrong syntax? It doesn't redirect the way I want it to be. Thanks!


回答1:


Am I missing something in here? Or a wrong syntax? It doesn't redirect the way I want it to be. Thanks!

You really didn't explain much about what is happening and the result you are getting so that someone can tell why you are getting the result you are getting.

However in general you can't use mod_alias (Redirect) to redirect a query string it won't work.

You have to use mod_rewrite, which it seems like you were trying to do. However you don't want to carry over the query string with the redirect so you need to use ? in the rewrite URL.

So if you have a URL like so

http://www.example.com/?page=services/branddevelopment

Then your rule would be

RewriteCond %{QUERY_STRING} ^page=services/branddevelopment$
RewriteRule ^(.*)$ http://domain.com/?   [R=301,L]


来源:https://stackoverflow.com/questions/33218115/htaccess-301-redirect-with-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!