views:

146

answers:

2

I want to convert this URL:

mysite.com/cgi-bin/test.cgi/some_random_numbers_and_letters/http/www.somewebsite.com

into:

mysite.com/www.somewebsite.com

I also want to convert this URL:

mysite.com/addname.php

into:

mysite.com/add/

How do I do that?

+4  A: 

Take a look at this blog post and you will learn how to use mod_rewrite and practice yourself.

Nathan Campos
Good answer. I learnt everything I know (not very much, admittedly, but enough for this question) from http://www.workingwith.me.uk/articles/scripting/mod_rewrite
Skilldrick
+1  A: 

Within .htaccess or apache2.conf

Rewrite Engine On
Rewrite Rule ^(www\.)?([a-zA-Z]+)\.(.{1-5})$ cgi-bin/test.cgi/letters/http/$1$2$3
Rewrite Rule ^addname.php$ cgi-bin/addname.cgi
Rewrite Rule ^add/?$ cgi-bin/addname.cgi

EDIT:

Rewrite Engine On
Rewrite Rule ^add/(.*)$ cgi-bin/addname.cgi$1
Rewrite Rule ^addname.php(\?(.*))$ cgi-bin/addname.cgi$1
RewriteCond %{REQUEST_URI} !^/$
Rewrite Rule ^((.*)\.)?(.*)(\.[A-Za-z\.]{2,8})(/.*)$ cgi-bin/test.cgi/?subdomain=$1&urlname=$2&tld=$3&path=$4 [L]

Fixed and actually tested the regex this time. The $1, $2,$3,$4 match the parts of the domain. The whole domain can be specified simply by using $1$2$3$4 I used a domain regex so only domains will be matched, and other website paths would not.

CodeJoust
it may not always be www. it coudl be any subdomain.
pingu
This should fix it.
CodeJoust