Forum Moderators: phranque

Message Too Old, No Replies

Trying to 301 Mod-Rewritten Wordpress Urls

help please!

         

stuntdubl

8:56 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm pretty clueless on mod-rewrite so this is one of my first endevors here. Any insight on how to 301 the old url's to the new ones would be greatly appreciated.

Example:
site.com/?p=213
301 to site.com/date/time/new-friendly-url/

site.com/?p=214
301 to site.com/date/time/new-friendly-url2/

etc. etc.

I notice there is [QSA,L] after most of the mod-rewrite stuff

I've seen [301,L] used before but have no clue what this means, and it didn't seem to work how I had hoped.

Really wanna do a site-wide sweeping 301 to the appropriate places in the very near future before I start hitting SE problems.

Here's an example of what's in my .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=55]
RewriteRule ^(about-red-fuzzy-widgets)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L]
RewriteRule ^(about-widget-fuzzy-stuff)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]
RewriteRule ^(about-fuzzy-widget-stuff)/(feed¦rdf¦rss¦rss2¦atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]
</IfModule>

jd01

10:41 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are not catching variables to pass through to the php pages anywhere. EG [a-z], or (.*), etc.

Change this:
RewriteRule ^(about-red-fuzzy-widgets)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L]

To this
RewriteRule ^([^/]+)/trackback/([0-9]+)\.html$ /index.php?pagename=$1&tb=1 [QSA,R=301,L]

Then change your friendly URL's to include the page or other variable you will need for the php file to work correctly:

/about-red-fuzzy-widgets/trackback/241.html

The .html is optional, I use it. The rules with two variables will need to have both instances in the new friendly URL.

I would change this:
RewriteRule ^(about-widget-fuzzy-stuff)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]

To this:
RewriteRule ^([^/]+)/feed/([a-z]+)/([0-9]+)\.html$ /index.php?pagename=$2&feed=$3 [QSA,NC,R=301,L]

(+) 1 or more of the characters.
[^/] anything that is not a /
QSA passes info as a query string.
NC designates No Case to verbiage.
R=301 Permanent Move Redirect.

Justin