site redirect sometimes malfunctions - php

I have a wordpress blog and don't want others to visit it. So I moved the blog to http://myhost.com/wordpress(sorry for hiding the name) and put an index.php in the root folder of http://myhost.com.
The index.php is simply random redirecting:
<?php
$sites = array("http://google.com", "http://youtube.com", "http://facebook.com", "http://twitter.com")
$len = count($sites);
$num = rand(0, $len - 1);
$str = "Location:".$sites[$num];
header($str);
?>
But sometimes (usually when the network is slow) when I visit http:/myhost.com/wordpress it redirects me to one of these sites I set. This also happens when I click links in the wordpress.
I cannot even identify whether it's browser's action or the server's.

It's probably because Wordpress's default action on 404 is to redirect to your main index.php
If you have access, you can change this in the .htaccess file.

Because you change directory of your Wordpress files but you don't change database datas. You have to change your WOrdpress blog URL from http://myhost.com/ to http://myhost.com/wordpress on wp-admin, (Settings > General section) .
If you can't login to your admin panel, you have to execute these SQL queries :
(don't forget to edit site URL and Wordpress table prefix (wp) !)
UPDATE wp_options SET option_value='http://myhost.com/wordpress' WHERE option_name='siteurl'
UPDATE wp_options SET option_value='http://myhost.com/wordpress' WHERE option_name='home'
Wordpress gets home url from database. Your database pointing home url to http://myhost.com/ . When you click Home Page link it will go to home url (http://myhost.com/)

Related

I have shifted my wordpress site from one host to another, after shift the website wp-admin is not open

I have shifted my wordpress site from one host to another, after shift the website wp-admin is not open and showing page cannot be displayed.http://www.surmonteinfogen.com/
Try To this URL www.surmonteinfogen.com/wp-login.php
It's Working and login to admin and Update Permalink Settings
You can update your URI with wp-login.php.
First of all search for this line of code
require( dirname(__FILE__) . ‘/wp-load.php’ );
After this line add this code.
update_option(‘siteurl’, ‘http://www.surmonteinfogen.com/’ );
update_option(‘home’, ‘http://www.surmonteinfogen.com/’ );
Update the modified file to server and point your browser to http://www.surmonteinfogen.com/wp-login.php
Now your URI are updated.
Remove the added code from wp-login.php and upload back to server. Now you can use the admin panel. :)

Magento subshops in subdirectory

I do have 5 shops:
http://www.mainshop.com
http://www.mainshop.com/subshop/
http://www.mainshop.com/subshops/
http://www.mainshop.com/subshops3/
http://www.mainshop.com/subshop4/
But everytime i click on the url for a categroy it keeps giving a Magento 404 error.
I did copy the index.php and htaccess to that subdirs and changed this line:
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'subshop1';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
I also changed the configuration of that specific website:
The 404 comes to cms pages and category pages. Can't figure it out.
Magento creates a full links like this:
{{unsecure_base_url}}../skin/
http://www.example.com/shop/../skin/
which wont work ofcourse... Try inserting the full links ;)
Like this:
http://www.example.com/skin/
Have you used store views for each shop on one magento installation? You should not have sub directories for each shop and no need to copy index.php or any other file to a subdirectory. I think you have misunderstood how magento store views work. What you should do is enable the option for the storecode to be shown in each URL. When you setup your store view you specify the code which will be used (e.g. subdir1, subdir2 or whatever you want it to be). You need to use store views as you are using the same base URL which you need to change back to be default for each store view so it should be http://www.mainshop.com/ for every store view or website. This will allow you to achieve what you are trying to, without modding any magento code. Read this document in the wiki for more information how to do it properly http://www.magentocommerce.com/knowledge-base/entry/overview-how-multiple-websites-stores-work/

Joomla! display article based on URL in stead of 404 page

We have a website based on Joomla! in the joomla directory, there are many other directories, i.e.:
C:\myjoomlawebsite
...joomla directories...
\myspecialdirectory
in "myspecialdirectory" there are resources that sometimes are available and other times are not available, as one would imagine, when a resource(php page) is not available, a 404 page is displayed.
What I would like to do is, "somehow" tell joomla that when the user tries to access a page located in "myspecialdirectory" and it's unavailable, it should show an article page rather than a 404.
if the user accesses mydomain.com/ <- all good
if the user accesses mydomain.com/existingpage.php <- all good
if the user accesses mydomain.com/unavailablepage.php <- a 404 should be shown
if the user accesses mydomain.com/myspecialdirectory/existingpage.php <- all good
if the user accesses mydomain.com/myspecialdirectory/unavilablepage.php <- here's where I want the user to see a article page in stead of a 404
Check this
For v1.5
if (($this->error->code) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}
For 1.6 & 1.7
if (($this->error->getCode()) == '404') {
Because that directory is outside of the Joomla framework, and you only want one directory to redirect to a Joomla page instead of a 404, then the easiest way to accomplish this is to use put a custom htaccess in the directory you want to redirect. You would want to add this to htaccess only in myspecialdirectory
ErrorDocument 404 /URL TO JOOMLA ARTICLE.php
For the standards-compliant solutions -- take a read here: http://magazine.joomla.org/component/k2/item/230

wordpress redirect to subdomain after login

I have my wordpress blog at www.mysite.com , also I have my own php application at a subdomain l.mysite.com
I want the login credentials of WordPress in my PHP application. I figured out that by including the wp-blog-header.php from the root to my app.
I can use the user info OK.
I wanted to redirect users to www.mysite.com/wp-login.php?redirect_to=l.mysite.com . You can see here that I am specifying the redirect_to parameter. Wordpress ignores this and redirects to admin panel.
I think that worpdress doesn't allow redirect to an "external domain" , which I think is specified in wp_safe_redirect() function in wordpress. Is there any plugin which could ignore some domain to which redirect can happen?
I see that there are many login specific redirect plugins but none which could do to a new doamin.
Check this Plugin: http://www.theblog.ca/wplogin-redirect
Looks like it does what you want. Probably it's outdated, however, it should be trivial to create a plugin that fits your need.
A filter to start with is login_redirect, there is another filter in wp_safe_redirect() so you can prevent the domain you want to use being blocked.
To monitor redirects, checkout my Better HTTP Redirects Plugin.
+1 to #hakre . I don't have 15 rep so I can't upvote. Repost incase his
function cleanup_allowed_redirect_hosts( $hosts )
{
$allowed_hosts = array('first.domain.com', 'second.domain.com', 'etc.domain.com');
return array_merge( $hosts, $allowed_hosts );
}
add_filter( 'allowed_redirect_hosts', 'cleanup_allowed_redirect_hosts', 10, 1 );

domains redirecting to specific pages

I have a main domain name associated with a WordPress site, and then I have a couple other domain names connected to that site as well.
I want the other two domains names to point/redirect to specific pages on the site rather than the index page, which is the default.
So when domain1.com is typed into the browser, it goes to maindomain.com/domain1page/ (this is how the permalinks are set up). Is this possible?
Add this to index.php and upload it the root of domain1.com
<?php
header("location:http://maindomain.com/domain1page/");
?>
OR if you do not have a Hosting package for domain1.com go to the Domain Manager and in Nameservers you can enter a URL to redirect your domain to there.
It's possible, but you must add each domain manually. Just redirect them to your page.
Sure - there are lots of different ways to do this. Some registrars let you set up redirects at the domain level. You could also have a website set up for each domain on your server, and then just redirect to the page you'd like from that. You could also use the httpd.ini file to detect the domain and redirect to the appropriate page.
This is a small script that might serve the purpose.
You should place this at the top of header.php in your wordpress theme.
The script will not do anything if a domain is not matched so wordpress will load normal page. Haven't tested, but it should work.
<?php
$host = $_SERVER["HTTP_HOST"];
//Setup Domains Directory Names Here
$domain1 = 'domainname1.com';
$domain1_dir = 'domain1directoryhere';
$domain2 = 'domainname2.com';
$domain2_dir = 'domain2directoryhere';
$domain3 = 'domainname3.com';
$domain3_dir = 'domain3directoryhere';
//Redirects to directory depending domain.
switch (true){
case (preg_match("/$domain1/",$host)):
header("location:/$domain1_dir");
break;
case (preg_match("/$domain2/",$host)):
header("location:/$domain2_dir");
break;
case (preg_match("/$domain3/",$host)):
header("location:/$domain3_dir");
break;
}
?>

Categories