Current location: Hot Scripts Forums » Other Discussions » Web Servers » Simple mod_rewrite help anyone?


Simple mod_rewrite help anyone?

Reply
  #1 (permalink)  
Old 05-18-09, 06:56 PM
jimmyjim jimmyjim is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Simple mod_rewrite help anyone?

Hi all,

Im trying to turn this
PHP Code:

http://www.somesite.com/videos/index.php?t=1&item=some-discription-of-sorts 

into this
PHP Code:

http://www.somesite.com/videos/1/some-discription-of-sorts/ 

using mod_rewrite.

both the 1 and the some-discription-of-sorts will be different each time.

If anyone could help it would be much appreciated

thanks.

Last edited by jimmyjim; 05-18-09 at 07:05 PM.
Reply With Quote
  #2 (permalink)  
Old 05-18-09, 07:25 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
RewriteEngine On
RewriteRule "videos/index.php?t=([^&]*)&item=(.*)$" $1/$2

== or ==

RewriteRule "videos/([^\/]*)/([^\/]*)/$" videos/index.php?t=$1&item=$2

(In case you want the reverse)

Not tested.
Reply With Quote
  #3 (permalink)  
Old 05-18-09, 07:34 PM
jimmyjim jimmyjim is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks heaps for that wirehopper.
Reply With Quote
  #4 (permalink)  
Old 05-18-09, 08:06 PM
jimmyjim jimmyjim is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
did not seem to work for me?

Any suggestions?
Reply With Quote
  #5 (permalink)  
Old 05-18-09, 08:24 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Here's a working example:

RewriteRule ^(.*\.tgz)$ tgz.php5?path=$1 [L]

^ = Beginning of the request string
( = Collect stuff starting now
.* = everything
\.tgz = until you find a period followed by tgz. The backslash ensures it is a period, not a wildcard
) = Done collecting
$ = End of request string

tgz.php5 is the new file that will be executed, and the collected stuff will be placed after path=

L = This is the last rewrite rule, don't do any more rewritting

The way it works is that if the file requested is tri.tgz, the request will be rewritten as tgz.php5?path=tri.tgz.

There are a lot of examples up at the Apache site - one way to test this stuff is to use simple scripts that just echo out what they get.

Another example:

RewriteEngine On
# Don't rewrite index.php5
RewriteRule ^index.php5$ - [L]
# Take every request for a .php5 file and pass it to index.php5 as 'page'
RewriteRule ^(.*)\.php5?$ index.php5?page=$1

This is tricky stuff - a certain amount of persistence is required as you're learning.

If you have a blog or other open source product running, you might want to look at their .htaccess file.
Reply With Quote
  #6 (permalink)  
Old 05-18-09, 08:27 PM
jimmyjim jimmyjim is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
cool thanks for your help man ill take a look around apache's site
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Simple (well... simple for you maybe) addition script sd12013 Script Requests 1 09-05-08 06:25 PM
A few simple scripts aaroninwv Script Requests 6 03-20-08 11:01 AM
Not really that Simple mab The Lounge 4 12-05-06 04:57 PM
need help simple question, but need it right. 0o0o0 PHP 3 01-31-06 04:21 PM
Need Simple Forum & Knowledgebase Norm1 Script Requests 1 01-31-06 01:08 AM


All times are GMT -5. The time now is 01:29 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.