Htaccess: Redirect: Difference between revisions

Moved to new category; Additional grammar and cleanup edits.
(Punctuation and grammatical changes; some clarification.)
(Moved to new category; Additional grammar and cleanup edits.)
 
Line 2: Line 2:
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
{|  
{|  
|[[Image:uc_small_logo.gif | MPG UniCenter]] ||
 
.htaccess:  
.htaccess:  
[[Htaccess: Introduction | Introduction]] |   
[[Htaccess: Introduction | Introduction]] |   
Line 20: Line 20:
'''Redirect'''
'''Redirect'''


The Redirect .htaccess command 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 want to have old links (saved by a user) still function and be redirected to your new page location, or even a new page name.
The Redirect .htaccess command is very powerful. You can redirect files or complete directories. Why would you want to do this? A typical example would be that you have changed the structure of your site but want to have old links (saved by a user) still function and be redirected to your new page location, or even a new page name.


== Redirect format ==
== Redirect format ==
Line 44: Line 44:
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.


=== Folder Redirect ===
=== Directory (Folder) Redirect ===
Suppose that all you have done is to rename a folder (and possibly 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 to rename a directory (and possibly moved it to another location); however all the files still have their original names. Redirecting a directory is similar to the above; for example:


'''Redirect /olddirectory <nowiki>http://yoursite.com/newdirectory</nowiki>'''
'''Redirect /olddirectory <nowiki>http://yoursite.com/newdirectory</nowiki>'''
Line 60: Line 60:


== Directory example 1 ==
== Directory example 1 ==
Using our '''errors''' folder, make a copy of it and rename it to '''moved'''.
Using our '''errors''' directory, make a copy of it and rename it to '''moved'''.


{|
{|
Line 68: Line 68:
|-style="background:#f9f9f9"
|-style="background:#f9f9f9"
|
|
# Navigate to the root folder '''www'''.
# Navigate to the root directory '''www'''.
# Open the '''.htaccess''' file
# Open the '''.htaccess''' file
# Add the command shown on the right last line.
# Add the command shown on the right last line.
Line 101: Line 101:
'''Testing'''
'''Testing'''


# Run the server using Start.exe
# (Re)start the server.
# In the browser address bar, type '''<nowiki>http:/localhost/old</nowiki>'''
# In the browser address bar, type '''<nowiki>http:/localhost/old</nowiki>'''
# You will be redirected to the folder '''<nowiki>http://localhost/moved/</nowiki>'''
# You will be redirected to the directory '''<nowiki>http://localhost/moved/</nowiki>'''


== Directory example 2 ==
== Directory example 2 ==
Open the file '''not_found.html''' contained in the folder that was moved and add some more text to distinguish it from the original.
Open the file '''not_found.html''' contained in the directory that was moved and add some more text to distinguish it from the original.


'''Testing'''
'''Testing'''
# Run the server using Server_Start.bat
# (Re)start the server.
# In the browser address bar type '''<nowiki>http:/localhost/old/not_found.html</nowiki>'''
# In the browser address bar type '''<nowiki>http:/localhost/old/not_found.html</nowiki>'''
# You will be redirected to the file '''<nowiki>http://localhost/moved/not_found.html</nowiki>'''
# 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.
And so forth. Experiment with files; it is similar to the directory example.


== Practical Example ==
== 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, so to avoid the frustration of not finding an article, users are redirected to the appropriate page on the Wiki.
After UniCenter had been around for nearly two years, it started to become unmanageable, hence the move over to the Wiki. Many web sites linked to various pages on UniCenter, so to avoid the frustration of not finding an article, users were redirected to the appropriate page on the Wiki.


Below is a small extract from my .htaccess file, where you will see I am using page redirection:  
Below is a small extract from a UniCenter .htaccess file, where you will see the use of page redirection:  


<pre>
<pre>
Line 144: Line 144:
----
----


[[Category: Support]]
[[Category: Apache Configuration]]
[[Category: Troubleshooting ]]
[[Category: Application]]
[[Category: Development]]