<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Xavisys&#187; redirect</title> <atom:link href="http://xavisys.com/tag/redirect/feed/" rel="self" type="application/rss+xml" /><link>http://xavisys.com</link> <description>WordPress Plugins and Custom WordPress Development</description> <lastBuildDate>Thu, 15 Jul 2010 17:58:50 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <atom:link rel='hub' href='http://xavisys.com/?pushpress=hub'/> <item><title>Cell phone safe redirecting with mod_rewrite</title><link>http://xavisys.com/cell-phone-safe-redirecting-with-mod_rewrite/</link> <comments>http://xavisys.com/cell-phone-safe-redirecting-with-mod_rewrite/#comments</comments> <pubDate>Thu, 26 Jul 2007 23:45:18 +0000</pubDate> <dc:creator>Aaron D. Campbell</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[redirect]]></category><guid
isPermaLink="false">http://xavisys.com/cell-phone-safe-redirecting-with-mod_rewrite/</guid> <description><![CDATA[This is an update to Redirecting all ServerAliases to a preferred domain with mod_rewrite. In that article I solved a problem that I was having where I needed to redirect all ServerAlias options to just one domain, preserving the ssl preference. However, we have a lot of users on cell phones. Some of the simple [...]]]></description> <content:encoded><![CDATA[<p>This is an update to <a
href="http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/">Redirecting all ServerAliases to a preferred domain with mod_rewrite</a>.  In that article I solved a problem that I was having where I needed to redirect all ServerAlias options to just one domain, preserving the ssl preference.  However, we have a lot of users on cell phones.  Some of the simple cell phones (like the Motorolla Razr) do NOT like addresses that are missing the www.  A simple url like http://mysite.com?u=user&amp;p=password would not work, because it didn&#8217;t store the session cookie properly.  Adding a www causes the cookies to work, but our ssl certificate is for mysite.com and having the www in that case causes warnings, and I still wanted to redirect our .net and .org TLDs.  I ended up deciding that having the www would be ok as long as the user was NOT trying to use SSL.  Here is how I did it:</p><pre class="brush: bash;">
&lt;ifmodule&gt;
RewriteEngine On
RewriteCond %{SERVER_PORT}%{HTTP_HOST}  !^(443|80(www\.)?)?mysite\.com [NC]
RewriteCond %{HTTP_HOST}                ^(www\.)?
RewriteCond %{SERVER_PORT}s%1           ^80s(www\.)?|443((s)(www\.))?$
RewriteRule ^(.*)                       http%3://%1mysite.com/$1 [L,R=301]
&lt;/ifmodule&gt;
</pre><p>Again, this is in the .htaccess file.  In the end, a user using SSL is <em>always</em> sent to https://mysite.com.  Standard connections are redirected to .com, but their www selection is preserved.<br
/><h3 class='related_post_title'>Related Posts:</h3><ul
class='related_post'><li><a
href='http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/' title='Redirecting all ServerAliases to a preferred domain with mod_rewrite'>Redirecting all ServerAliases to a preferred domain with mod_rewrite</a></li><li><a
href='http://xavisys.com/php-function-to-redirect-a-user-with-a-message/' title='PHP function to Redirect a user with a message'>PHP function to Redirect a user with a message</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://xavisys.com/cell-phone-safe-redirecting-with-mod_rewrite/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>PHP function to Redirect a user with a message</title><link>http://xavisys.com/php-function-to-redirect-a-user-with-a-message/</link> <comments>http://xavisys.com/php-function-to-redirect-a-user-with-a-message/#comments</comments> <pubDate>Tue, 10 Jul 2007 03:51:19 +0000</pubDate> <dc:creator>Aaron D. Campbell</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[redirect]]></category><guid
isPermaLink="false">http://xavisys.com/php-function-to-redirect-a-user-with-a-message/</guid> <description><![CDATA[One of the common things that you need to do in PHP is redirect a user, and display a message on whatever page you are sending them to. There are a lot of reasons for this, but the most common is to avoid a user refresh from resubmitting a form. Instead, process the form data, [...]]]></description> <content:encoded><![CDATA[<p>One of the common things that you need to do in PHP is redirect a user, and display a message on whatever page you are sending them to.  There are a lot of reasons for this, but the most common is to avoid a user refresh from resubmitting a form.  Instead, process the form data, and redirect the user (even if you redirect them to the same page).  Here is a function I use for this very purpose.  It requires that you are using sessions.  It stores the message in the session, and passes a has in the URL.  This way, you can use any length message you want, and display it only once.<br
/> <span
id="more-46"></span><br
/> First, the function:</p><pre class="brush: php;">/**
* This function redirects to a specified page (current page by default), but
* passes along a message in the users SESSION.  It passes a GET var that tells
* where that message is.  Used properly, this will avoid giving the user a
* duplicate message on page refresh.
*
* @param string $message - Message to pass along via session
* @param string[optional] $page - page to redirect to (with leading /)
*/
function redirect($message, $page=FALSE) {
	$my_get = array();
	$_GET['message'] = set_session_message($message);
	foreach ($_GET as $n=&amp;gt;$v) {
		$my_get[] = &amp;quot;{$n}={$v}&amp;quot;;
	}
	if (count($my_get) &amp;gt; 0) {
		$my_get = '?'.implode('&amp;amp;',$my_get);
	} else {
		$my_get = '';
	}

	if (is_string($page)) {
		$location = $page;
	} else {
		$location = $_SERVER['SCRIPT_NAME'];
	}

	$http = (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS'])!='on')?'http':'https';

	header(&amp;quot;Location: {$http}://{$_SERVER['HTTP_HOST']}{$location}{$my_get}&amp;quot;);
	exit;
}

/**
 * Set a session message
 *
 * @param string $message Message to set
 *
 * @return string - Message ID which is the $_SESSION index that holds the message
 */
function set_session_message($message) {
	$message_id = sha1(microtime(true));
	$_SESSION[$message_id] = $message;

	return $message_id;
}
</pre><p>Use it like this:</p><pre class="brush: php;">
//To redirect to the current page
redirect('Place your message here');
//To go to another page
redirect('Place your message here', '/next_page.php');
</pre><p>Now, you will want to display the message.  I use this code in my template file</p><pre class="brush: php;">
if (isset($_GET['message']) &amp;amp;&amp;amp; isset($_SESSION[$_GET['message']])) {
	echo $_SESSION[$_GET['message']]&amp;quot;;
	unset($_SESSION[$_GET['message']]);
}
</pre><p>In this way, the message is displayed, but then unset so it&#8217;s not displayed again on refresh.</p><p>Simple and effective.<br
/><h3 class='related_post_title'>Related Posts:</h3><ul
class='related_post'><li><a
href='http://xavisys.com/howto-create-stream-csv-php/' title='Howto: Create and Stream a CSV with PHP'>Howto: Create and Stream a CSV with PHP</a></li><li><a
href='http://xavisys.com/wordpress-25-shortcodes/' title='WordPress 2.5 Shortcodes'>WordPress 2.5 Shortcodes</a></li><li><a
href='http://xavisys.com/wordpress-should-update-get_sidebar-to-work-with-multiple-sidebars/' title='Wordpress Should Update get_sidebar to Work With Multiple Sidebars'>WordPress Should Update get_sidebar to Work With Multiple Sidebars</a></li><li><a
href='http://xavisys.com/cell-phone-safe-redirecting-with-mod_rewrite/' title='Cell phone safe redirecting with mod_rewrite'>Cell phone safe redirecting with mod_rewrite</a></li><li><a
href='http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/' title='Redirecting all ServerAliases to a preferred domain with mod_rewrite'>Redirecting all ServerAliases to a preferred domain with mod_rewrite</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://xavisys.com/php-function-to-redirect-a-user-with-a-message/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Redirecting all ServerAliases to a preferred domain with mod_rewrite</title><link>http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/</link> <comments>http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/#comments</comments> <pubDate>Sat, 07 Jul 2007 01:35:46 +0000</pubDate> <dc:creator>Aaron D. Campbell</dc:creator> <category><![CDATA[apache]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[redirect]]></category><guid
isPermaLink="false">http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/</guid> <description><![CDATA[I had a domain that I owned three TLDs for. I had the .com, the .net, and the .org. These all go to the same site using ServerAlias directives in the apache config. As do the www versions of each. However, I preferred to have them all go to mysite.com with no www. To add [...]]]></description> <content:encoded><![CDATA[<p>I had a domain that I owned three TLDs for.  I had the .com, the .net, and the .org.  These all go to the same site using ServerAlias directives in the apache config.  As do the www versions of each.  However, I preferred to have them all go to mysite.com with no www.  To add to the confusion, the site allows (but does not require) SSL, so the user&#8217;s SSL state needed to be preserved during all this rewriting.  Here is what I came up with, and it works great.</p><pre class="brush: bash;">
&lt;ifmodule&gt;
RewriteEngine On
RewriteCond %{HTTP_HOST}    !^mysite\.com [NC]
RewriteCond %{HTTP_HOST}    !=&quot;&quot;
RewriteCond %{SERVER_PORT}s ^(80s|443(s))$
RewriteRule ^(.*)          http%2://mysite.com/$1 [L,R=301]
&lt;/ifmodule&gt;
</pre><h3 class='related_post_title'>Related Posts:</h3><ul
class='related_post'><li><a
href='http://xavisys.com/cell-phone-safe-redirecting-with-mod_rewrite/' title='Cell phone safe redirecting with mod_rewrite'>Cell phone safe redirecting with mod_rewrite</a></li><li><a
href='http://xavisys.com/php-function-to-redirect-a-user-with-a-message/' title='PHP function to Redirect a user with a message'>PHP function to Redirect a user with a message</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://xavisys.com/redirecting-all-serveraliases-to-a-preferred-domain-with-mod_rewrite/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching using apc
Content Delivery Network via cdn.xavisys.com

Served from: xavisys.com @ 2010-09-09 11:52:55 -->