But I don't want to change manualy all my links, so I am trying to use a redirect rule at the same time.
You must manually change all your links. Ok, it is technically possible to do this without changing your links (see below) - however, this will have a serious negative effect on your users and SEO. If you don't change your links in the HTML then:
- You are still exposing the old URL to users and search engines
- Everytime a user follows a link on the page they will be externally redirected. This will potentially double the number hits to your server and flood your logs with 3xx responses. (Although a 301 response will, by default, get cached by the browser for a period of time.)
- Likewise, search engines are going to continually crawl the old URLs, as these are the ones exposed in your HTML.
Rewrite and redirect in .htaccess
at the same time
As noted above, you should already have changed the links in your HTML.
However, you would still need to implement a redirect like this when you are changing an existing URL structure as you need to redirect search engines that have already indexed the old URL structure in order to preserve SEO. You also need to redirect users and other third-party sites that might have bookmarked or linked to the old URLs. If you don't implement such a redirect when changing an existing URL structure then you are effectively starting SEO from zero again.
If this is a brand new site then this redirect is not necessarily required, as the old URL should never be exposed.
So, you need to redirect:
example.com/vote.php?ranking=<ranking>&lang=<lang>&period=<period>&provider=<provider>
to:
example.com/<lang>/<ranking>/<period>/<provider>
Note that the <lang>
and <ranking>
parameter values are reversed - as in your example.
If all parameters are mandatory and always in the order stated then you can do something like the following in .htaccess
, before the existing rewrite:
RewriteCond %{QUERY_STRING} ^ranking=([^&]+)&lang=([^&]+)&period=([^&]+)&provider=([^&]+)
RewriteRule ^vote\.php$ /%2/%1/%3/%4 [QSD,R,L]
This completely removes the original query string from the request.
However, if some or all of the URL parameters can be omitted from the query string (which your rewrite seems to imply) and/or can be placed in a different order (ie. were you consistent in how the old URLs were constructed?) then this will complicate matters.