Mobile app version of vmapp.org
Login or Join

Login to follow query

More posts by @Shelley277

2 Comments

Sorted by latest first Latest Oldest Best

 

@Shelley277

You could do it in the PHP itself

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: 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$ www.domain.com/course/view.php?id=2&section=1 [L,R=301]

10% popularity Vote Up Vote Down


 

@Jamie184

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!

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme