[SOLVED] Htaccess redirects

This is a discussion on "[SOLVED] Htaccess redirects" within the PHP Forum section. This forum, and the thread "[SOLVED] Htaccess redirects are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 6th, 2007, 19:44
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
[SOLVED] Htaccess redirects

I have an htaccess file set up to mod_rewrite my query string. Currently I have this :

Code: Select all
RewriteEngine on
RewriteRule ^([0-9]+)/?$ play.php?id=$1
Now this would redirect from /play.php?id=20 to /20.

But it also means you can access it at /20/ which I don't want.

How would I update my file to redirect back to just /20 if the visitor arrives at the location with a trailing slash?

Thanks guys. This ones really doing my head in.
Reply With Quote

  #2 (permalink)  
Old Dec 6th, 2007, 20:34
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Htaccess redirects

Use the following code to access how the file is accessed:
PHP: Select all

$_SERVER['REQUEST_URI']; 

This would give "/20/".
You could do something like so:
PHP: Select all

if ($_SERVER['REQUEST_URI'] != "/20") {
header("Location: /20");

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Dec 6th, 2007, 21:00
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: Htaccess redirects

That's such a simple solutions. Works perfectly.

Cheers mate.

Don't know why I didn't think of that myself
Reply With Quote
  #4 (permalink)  
Old Dec 6th, 2007, 21:12
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: [SOLVED] Htaccess redirects

You're welcome
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer domains and redirects Preston Hosting & Domains 7 Oct 11th, 2007 06:47
automatic redirects benbacardi Classic ASP 2 Sep 13th, 2004 09:02


All times are GMT. The time now is 02:11.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43