J_C
J_C

Reputation: 27

htaccess redirect help please

I previously asked this question and the answer did not seem to work as required - it also required an addition.

Users are provided with unique URL's, ie: exampleurl.com/AQ4ILB9
AQ4ILB9 being the referral code

  1. I would like that URL above (or any referral URL) to display the contents of index.php (htaccess redirect?)
  2. I would like the non-www and www version of exampleurl.com, including example.com/index.php to be redirected to the top level in this format: http://www.exampleurl.com/
  3. I would like for example: $_GET['_url'] to hold the referral id (ie: AQ4ILB9) in index.php

How can I go about the above 3 all using htaccess?

Thanks!

Upvotes: 0

Views: 217

Answers (4)

Dunhamzzz
Dunhamzzz

Reputation: 14798

Replace example.com with your domain and put this in your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule (.*) /index.php?_url=$1 [L]

Should do the trick! You may not need the RewriteEngine On line if it's already there.

Upvotes: 0

soju
soju

Reputation: 25302

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)$ /index.php?_url=$1 [NC,L,QSA]

The first part is a 301 redirect to add www.

The second part will rewrite what you want, but not for existing files/directories.

Upvotes: 2

Lawrence Cherone
Lawrence Cherone

Reputation: 46602

RewriteRule ^/([A-Z0-9]+)$ index.php?_url=$1

Upvotes: 0

Kit
Kit

Reputation: 4105

Q) 1 & 3:

RewriteRule (.*) index.php?url=$1 [L,P]

Q) 2:

RewriteCond %{HTTP_HOST} ^exampleurl.com
RewriteRule (.*) http://www.exampleurl.com/$1 [R=301,L]

Upvotes: 1

Related Questions