Mobile app version of vmapp.org
Login or Join
Gonzalez347

: How to use a RewriteRule and Redirect 301 at the same time? I have my Url with multiple parameters: mydomain.com/?vote.php?ranking=parameter1&lang=parameter2&period=parameter3&provider=parameter4

@Gonzalez347

Posted in: #Htaccess #Redirects

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Gonzalez347

2 Comments

Sorted by latest first Latest Oldest Best

 

@Lee4591628

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.

10% popularity Vote Up Vote Down


 

@Heady270

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: www.example.com/$ranking/$lang/$period/$provider );
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme