Redirect for special characters

Redirect for special characters - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirect for special characters error on your web browser. Problem :


I want to set a redirect as below.



http://www.domain.com/course/view.php?id=2 TO http://www.domain.com/course/view.php?id=2&section=1



Can you please let me know how can this be set ?


Solution :

You could do it in the PHP itself



<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.domain.com/course/view.php?id=2&section=1");
?>



You could do it with mod_rewrite



RewriteEngine On
RewriteCond %QUERY_STRING ^id=2$
RewriteRule ^/?course/view.php$ http://www.domain.com/course/view.php?id=2&section=1 [L,R=301]



In .htaccess:



RewriteEngine On
RewriteCond %QUERY_STRING =id=2
RewriteRule ^course/view.php /course/view.php?section=1 [R=301,QSA,L]


If the query string matches exactly id=2 then externally redirect. The QSA flag combines the original query string with the new one, so the resulting URL is actually ?section=1&id=2 - but the order should not matter.



The other niggling thought is that you would perhaps be better handling the defaulting of URL params in your server-side code and set a rel="canonical" tag instead of redirecting.



UPDATE:




I tried the redirect from cPanel. From cPanel it does not accepts the ? & =




The redirection tool in cPanel can only handle simple redirects and to be honest I would avoid it if at all possible. When you add a redirect in cPanel it edits your .htaccess file. If you already have other directives in your .htaccess file then it has to be very clever not to break anything - and it does not appear to be that clever.



This no doubt depends on cPanel versions, but I tried to create a suitable redirect in cPanel. It didn't complain about the query string characters ? and & and allowed me to create the redirect. However, when examining the resulting directives in .htaccess it was completely wrong and would not have worked as intended!


We hope that this article has helped you resolve the redirects, , error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

Redirected urls show in serp, with the original permalink but with the title and meta of the target page

How can I redirect everything but the index as 410?

How do I redirect traffic only if being accessed from a specific port?