Simple 301 Redirects - Version 1.0

Version Description

  • Initial Release
Download this release

Release Info

Developer scottnelle
Plugin Icon 128x128 Simple 301 Redirects
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (3) hide show
  1. readme.txt +27 -0
  2. screenshot-1.jpg +0 -0
  3. wp-simple-301-redirects.php +167 -0
readme.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Simple 301 Redirects ===
2
+ Contributors: scottnelle
3
+ Tags: 301, redirect, url, seo
4
+ Requires at least: 1.5
5
+ Tested up to: 2.8.4
6
+ Stable tag: 1.0
7
+
8
+ Simple 301 Redirects provides an easy method of redirecting requests to another page on your site or elsewhere on the web.
9
+
10
+ == Description ==
11
+
12
+ Simple 301 Redirects provides an easy method of redirecting requests to another page on your site or elsewhere on the web. It's especially handy when you migrate a site to WordPress and can't preserve your URL structure. By setting up 301 redirects from your old pages to your new pages, any incoming links will be seemlessly passed along, and their pagerank (or what-have-you) will be passed along with them.
13
+
14
+ == Installation ==
15
+
16
+ 1. Upload Simple 301 Redirects to the `/wp-content/plugins/` directory
17
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
18
+ 1. Add redirects on the Settings > 301 Redirects page.
19
+
20
+ == Screenshots ==
21
+
22
+ 1. The admin interface
23
+
24
+ == Changelog ==
25
+
26
+ = 1.0 =
27
+ * Initial Release
screenshot-1.jpg ADDED
Binary file
wp-simple-301-redirects.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Simple 301 Redirects
4
+ Plugin URI: http://www.scottnelle.com/simple-301-redirects-plugin-for-wordpress/
5
+ Description: Create a list of URLs that you would like to 301 redirect to another page or site
6
+ Version: 1.0
7
+ Author: Scott Nellé
8
+ Author URI: http://www.scottnelle.com/
9
+ */
10
+
11
+ /* Copyright 2009 Scott Nellé (email : theguy@scottnelle.com)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2 of the License, or
16
+ (at your option) any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+
28
+ if (!class_exists("Simple301redirects")) {
29
+ class Simple301Redirects {
30
+ /*
31
+ generate the link to the options page under settings
32
+ */
33
+ function create_menu()
34
+ {
35
+ add_options_page('301 Redirects', '301 Redirects', 10, '301options', array($this,'options_page'));
36
+ }
37
+
38
+ /*
39
+ generate the options page in the wordpress admin
40
+ */
41
+ function options_page()
42
+ {
43
+ ?>
44
+ <div class="wrap">
45
+ <h2>Simple 301 Redirects</h2>
46
+
47
+ <form method="post" action="options-general.php?page=301options">
48
+
49
+ <table>
50
+ <tr>
51
+ <th>Request</th>
52
+ <th>Destination</th>
53
+ </tr>
54
+ <tr>
55
+ <td><small>example: /about.htm</small></td>
56
+ <td><small>example: <?php echo get_option('home'); ?>/about/</small></td>
57
+ </tr>
58
+ <?php echo $this->expand_redirects(); ?>
59
+ <tr>
60
+ <td><input type="text" name="301_redirects[request][]" value="" style="width:15em" />&nbsp;&raquo;&nbsp;</td>
61
+ <td><input type="text" name="301_redirects[destination][]" value="" style="width:30em;" /></td>
62
+ </tr>
63
+ </table>
64
+
65
+ <p class="submit">
66
+ <input type="submit" name="submit_301" class="button-primary" value="<?php _e('Save Changes') ?>" />
67
+ </p>
68
+ </form>
69
+ </div>
70
+ <?php
71
+ } // end of function options_page
72
+
73
+ /*
74
+ utility function to return the current list of redirects as form fields
75
+ */
76
+ function expand_redirects(){
77
+ $redirects = get_option('301_redirects');
78
+ $output = '';
79
+ if (!empty($redirects)) {
80
+ foreach ($redirects as $request => $destination) {
81
+ $output .= '
82
+
83
+ <tr>
84
+ <td><input type="text" name="301_redirects[request][]" value="'.$request.'" style="width:15em" />&nbsp;&raquo;&nbsp;</td>
85
+ <td><input type="text" name="301_redirects[destination][]" value="'.$destination.'" style="width:30em;" /></td>
86
+ </tr>
87
+
88
+ ';
89
+ }
90
+ } // end if
91
+ return $output;
92
+ }
93
+
94
+ /*
95
+ save the redirects from the options page to the database
96
+ */
97
+ function save_redirects($data)
98
+ {
99
+ $redirects = array();
100
+
101
+ for($i = 0; $i < sizeof($data['request']); ++$i) {
102
+ $request = trim($data['request'][$i]);
103
+ $destination = trim($data['destination'][$i]);
104
+
105
+ if ($request == '' && $destination == '') { continue; }
106
+ else { $redirects[$request] = $destination; }
107
+ }
108
+
109
+ update_option('301_redirects', $redirects);
110
+ }
111
+
112
+ /*
113
+ Read the list of redirects and if the current page
114
+ is found in the list, send the visitor on her way
115
+ */
116
+ function redirect()
117
+ {
118
+ // this is what the user asked for
119
+ $userrequest = str_replace(get_option('home'),'',$this->getAddress());
120
+ $userrequest = rtrim($userrequest,'/');
121
+
122
+ $redirects = get_option('301_redirects');
123
+ if (!empty($redirects)) {
124
+ foreach ($redirects as $storedrequest => $destination) {
125
+ // compare user request to each 301 stored in the db
126
+ if($userrequest == rtrim($storedrequest,'/')) {
127
+ wp_redirect($destination, 301);
128
+ exit();
129
+ }
130
+ else { unset($redirects); }
131
+ }
132
+ }
133
+ } // end funcion redirect
134
+
135
+ /*
136
+ utility function to get the full address of the current request
137
+ credit: http://www.phpro.org/examples/Get-Full-URL.html
138
+ */
139
+ function getAddress()
140
+ {
141
+ /*** check for https ***/
142
+ $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
143
+ /*** return the full address ***/
144
+ return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
145
+ }
146
+
147
+ } // end class Simple301Redirects
148
+
149
+ } // end check for existance of class
150
+
151
+ // instantiate
152
+ $redirect_plugin = new Simple301Redirects();
153
+
154
+ if (isset($redirect_plugin)) {
155
+ // add the redirect action, high priority
156
+ add_action('init', array($redirect_plugin,'redirect'), 1);
157
+
158
+ // create the menu
159
+ add_action('admin_menu', array($redirect_plugin,'create_menu'));
160
+
161
+ // if submitted, process the data
162
+ if (isset($_POST['submit_301'])) {
163
+ $redirect_plugin->save_redirects($_POST['301_redirects']);
164
+ }
165
+ }
166
+
167
+ ?>