4

I am newbie on Joomla. I have bought a new domain for my site that I want to use and have my site running on two different server under the 2 domain accordingly.

I need to redirect the old domain and all its urls to the new domain at the new server.

I tried changing from components > Redirect manager- set the expired url and New url, but didn't see any changes.

update:

I added these lines to my htaccess in the localhost site. But they don't work.

Modified .htaccess-

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost:8888/woodypub\$ [OR]
RewriteCond %{HTTP_HOST} ^localhost:8888/woodypub\$
RewriteRule (.*)$ http://www.yourNewDomain.com/$1 [R=301,L]
</IfModule>

My old .htaccess -

##
# @package   Joomla
# @copyright    Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
# @license   GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
  • 1
    you have 2 domains and want to redirect all traffic from the old domain to the new one? – FFrewin Jan 9 '16 at 6:51
  • @ FFrewin- yes. – Sanjuktha sandesh Jan 11 '16 at 0:53
  • 1
    To see if mod_rewrite is present in your local environment, comment out the 2 rewrite conditions and see if the redirection occurs. Those 2 conditions aren't correct and will never been met, as obviously the localhost:8888/woodypub isn't the HTTP_HOST var. But I don't see why you want to redirect the localhost site. Anyway, I am going to update my answer with new directives for the localhost case. – FFrewin Jan 14 '16 at 14:46
  • @FFrewin- I wanted to redirect the server site itself,but first i am testing it out on the localhost,since a newbie just afraid to try it out directly on the server,so once success on the localhost can try it on the server. – Sanjuktha sandesh Jan 15 '16 at 1:07
5

There are various techniques you can do to redirect an old domain to a new one and many depend on your server and site configuration.

If you are hosting on Apache server, then one of the most common is to redirect all pages urls of the old domain to the corresponding pages of the new domain - using Apache's mod_rewrite - assuming you have kept the same pages/urls structure.

So in the root of your old domain, you can place a .htaccess containing the lines below (or add them to the current .htaccess file if exists):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourOldDomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yourOldDomain\.com$
RewriteRule (.*)$ http://www.yourNewDomain.com/$1 [R=301,L]
</IfModule>

This will redirect all pages to the new Domain. So if someone tries to reach a page like:

www.yourOldDomain.com/yourSpecialPage

he will be redirected to:

www.yourNewDomain.com/yourSpecialPage

Note that: if under the new domain you have changed the pages/urls structure, then you might want to handle these changes with special redirections under the new Domain. The Joomla's core redirect component could help, or you can use 3rd party SEF extensions like SH404SEF, or handle url per url redirections in the .htaccess of your new domain.

Update for your localhost - based on what I saw from your htaccess code in your question:

I see you want to redirect the localhost site to the new domain (why???) and you tried to use what I suggested above in your .htaccess file.
But there is no chance for the rewrite rule to occur, because the rewrite conditions will never be satisfied. And that's because the localhost:8888/woodypub won't be equal to the HTTP_HOST S_SERVER variable.

So normally, in your case, something like below should work:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost:8888
RewriteCond %{REQUEST_URI} woodypub\/(.*)$
RewriteRule ^(.*)$ http://www.yourNewDomain.com/$1 [R=301,L]
</IfModule>

So briefly what the above does is:

  1. Checking if 2 conditions are both met:
    a. HTTP_HOST = localhost:8888
    AND
    b. REQUEST_URI = woodypub/ (with anything after it)

  2. And if yes, then the rewriterule will occur and will redirect to the new location - preserving everything that might come after the woodypub URI.

  • i edited my .htaccess as you given,but nothing happened :( ,but the info provided my Max worked.Thanks for the help. – Sanjuktha sandesh Jan 13 '16 at 8:12
  • 1
    @sa-7: Actually if mod_rewrite is present in your old host, it should work - assuming you have replaced the yourOldDomain\.com properly with your own domain. Also you may want to keep in mind that although Max's answer works - it's not the ideal solution and not good for SEO. It also doesn't redirect pageurl to page url. – FFrewin Jan 13 '16 at 9:30
  • @FFrewin- Ohk thanks for the info,yes i changed the url properly.Should i change the entire code in .htaccess and replace it just with this? – Sanjuktha sandesh Jan 14 '16 at 0:43
  • if trying on the localhost in the same manner it should work right?I replaced my entire .htaccess code and placed just yours,but still no change. – Sanjuktha sandesh Jan 14 '16 at 1:44
  • 1
    @sa-7: It depends on your localhost environment. If it doesn't then mod_rewrite might not be available. Also it depends on the rewrite conditions, since the rewrite rule will try to meet those - so you have to make sure that the conditions are written right. To test if mod_rewrite exists, comment out the rewrite conditions and see if the rewrite rule alone works. But sorry I don't understand - why you want to redirect the localhost site? – FFrewin Jan 14 '16 at 14:17
2

You can try edit your index.php and add In first line after < php? tag this code:

header("Location: http://newsite.com");
die();

I holpe this helps.

  • 2
    For everyone that might arrive here looking for the same, note that although this answer will create a redirection and is accepted, it is not actually the ideal solution to redirect an old domain to a new one. – FFrewin Jan 13 '16 at 9:47
1

Enable the "System - Redirect" plugin in Extensions -> Plugins.

In normal operation of the website, I recommend setting Extensions -> Plugins -> System - Redirect -> Collect URLs to "Disabled" otherwise thousands of failed urls tend to be collected in the database and there is no easy way to purge these except via phpMyAdmin or similar.

Edit: A "Purge Unpublished" button has been added since Joomla 3.5.0 to make it easier to purge unwanted urls from the database. Thank-you Brian Teeman.

  • It is already enabled under "System - Redirect" plugin in Extensions -> Plugins. "Collect URLs" to disabled means? – Sanjuktha sandesh Jan 8 '16 at 6:43
  • is it under redirect manager as i mentioned once we set the new url,we should select the option disabled? – Sanjuktha sandesh Jan 8 '16 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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