Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2009, 12:38 PM   PM User | #1
butlins
Regular Coder

 
Join Date: Aug 2006
Location: Cardiff, UK
Posts: 141
Thanks: 15
Thanked 2 Times in 2 Posts
butlins is an unknown quantity at this point
Zeus mod rewrite 301 redirects

I'm currently using Names.co.uk as a host for a few of my client's sites, and thought I'd post up a couple of bits of code which I'm using for 301 redirects, in the hope it saves people the time I've spent.

The code is quite a lot shorter than other examples I've seen. I'll add the caveat that this has been achieved by trial and error, and I've not got that much experience with Zeus. They work, but I can't vouch for security or error checking...

Namesco use a rewrite.script file, saved in the root directory of the website, as the functional equivalent of Apache's .htaccess file. I was migrating a site from .asp to .php and needed to organise a 301 redirect which kept the filename identical and the querystring intact - news.asp?NewsNo=500 mapped onto news.php?NewsNo=500

I did this with the following bit of script:
Code:
RULE_0_START:
# Rewrites URIs with .asp suffix to .php and preserves querystring values
match URL into $ with ^(.*)\.asp(.*)$
if not matched then goto RULE_0_END
if matched then
	set URL=$1.php$2
	set RESPONSE = 301
	set OUT:Location = %{URL}
	set BODY = Please try <a href="%{URL}">here</a> instead\n
goto END
RULE_0_END:
This became the basis of other rewrite scripts. For example, to redirect to a Flickr account photostream from a short URL (http://[www.domain.com]/flickr for example), I used:
Code:
RULE_1_START:
match URL into $ with ^\/flickr$
if not matched then goto RULE_1_END
if matched then
	set URL = http://www.flickr.com/photos/[name of photostream]/
	set RESPONSE = 301
	set OUT:Location = %{URL}
	set BODY = Please try <a href="%{URL}">here</a> instead\n
goto END
RULE_1_END:
Hope others find this helpful, as there didn't seem to be much in the way of real world examples that I could use as the basis for my needs.
__________________
If anyone asks my boss, this counts as work, okay?
butlins is offline   Reply With Quote
Reply

Bookmarks

Tags
301, mod_rewrite, namesco, redirect, zeus

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:50 AM.


Advertisement
Log in to turn off these ads.