3

I have my Url with multiple parameters:

mydomain.com/?vote.php?ranking=parameter1&lang=parameter2&period=parameter3&provider=parameter4

but I would like to change my urls to SEO friendly. My idea was to link my pages to:

mydomain.com/parameter1

..and I use this RewriteRule in .htaccess, to validate the new adress:

RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?   [NC]
RewriteRule .*    /vote.php?ranking=%2&lang=%1&period=%3&provider=%4  [L,NC]

But I don't want to change manualy all my links, so I am trying to use a redirect rule at the same time. Is it possible to use a redirect 301 and don't cause redirection loop?

4
  • 1
    Putting parameters into directory positions isn't necessarily better for SEO. Google doesn't care what your URLs look like as long as they are consistent. The biggest advantage with the directories is that the parameters can't be re-ordered, so you won't have duplicate content based on URLs that only vary in parameter order. In that case it helps ensure consistency. Dec 5, 2017 at 10:29
  • 1
    Even with the positional directories you still have some potential issues due to combinations of parameters. Are all combinations valid? There are a lot of combinations. Which ones will Googlebot be crawling? What do you do if the server encounters an invalid combination? Dec 5, 2017 at 10:30
  • 1
    You should do the work of changing your links. Having a redirect on every click is worse for SEO and user experience than having parameters on URLs. Dec 5, 2017 at 10:31
  • I was trying to show externally SEO addresses, but the page works internally with old parameters (and not changing anything in PHP/HTML code). Well, I must change the links... Thanks for your explanation!
    – Kalimero
    Dec 5, 2017 at 10:40

3 Answers 3

1

I commented that I have many concerns about your plan. It doesn't look great for SEO to me at all. However, you can do the redirects.

I would take the approach of adding a redirect=no parameter to your rewrite rule:

RewriteRule .*    /vote.php?ranking=%2&lang=%1&period=%3&provider=%4&redirect=no  [L,NC]

Then in vote.php you can distinguish between requests that should be redirected and requests that should not.

if (strcmp("no", $_GET['redirect']) !== 0) {
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: http://www.example.com/$ranking/$lang/$period/$provider");
}
1
  • You may not need the redirect=no URL param if the redirected URL doesn't contain any URL params.
    – MrWhite
    Nov 18, 2018 at 22:47
1

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.

-1

I use:

RewriteRule ... [L,R=301]

The rewrite does a 301 redirect. I'm not sure about whether this is a redirection loop or not though as I'm not familiar enough with the subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.