User Login    
   Register now!

Howtodude.NET / How to redirect www.example.com/index.php to www.example.com in XOOPS

howtodude 4/15 23:16
5
Howtodude.NET > Computers > Internet > CMS > XOOPS

Aim:

If a webpage on www.example.com/index.php shows the same content as www.example.com/ , you may consider a redirect in order to improve your site's ranking in search engines. The aim of this howto is to redirect this page.

How to redirect www.example.com/index.php to www.example.com in XOOPS:

Add something like this to your PHP file:

// redirect to avoid double content
if(strpos(getenv('REQUEST_URI'), '/index.php') === 0)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/");
}

This should do the redirect.

In case you have a multilingual site running on the XLanguage module, the situation will be slightly more complicated. You will have different index pages for each language, for example www.example.com/index.php?lang=en for English and  www.example.com/index.php?lang=fr for French. In addition, the content of www.example.com depends on a cookie that stores the language preferences.

For SEO reasons, it is better to have one page per URL. Let's say you want to ensure that www.example.com/index.php?lang=en becomes www.example.com and www.example.com/index.php?lang=fr to www.example.com/fr/. In this case, make sure that this phase is included in your .htaccess file:

RewriteEngine On
 

and add something like this to your .htaccess file:

# English
RewriteRule ^en$ / [R=301]
RewriteRule ^en/$ / [R=301]
DirectoryIndex index.php?lang=en
# French
RewriteRule ^fr$ /fr/ [R=301]
RewriteRule ^fr/$ /index.php?lang=fr [QSA,L]


Finally, add something like this to your index.php file:

// redirect to avoid double content
if(strpos(getenv('REQUEST_URI'), '/index.php?lang=fr') === 0)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/fr/");
}
elseif(strpos(getenv('REQUEST_URI'), '/index.php?lang=en') === 0)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/");
}
elseif(strpos(getenv('REQUEST_URI'), '/index.php') === 0)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/");
}

 

 

 

Disclaimer: this howto reflects the personal opinion of the writer.
The comments are owned by the poster. We aren't responsible for their content.
Add YOUR own howtos today!

It's fun, it's free, increase your productivity! Archive your own howtos on Howtodude.NET so that you can access these from everywhere at every time!

Register now!