Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite

mod rewrite guide

         

bheewhay

2:47 am on Nov 28, 2007 (gmt 0)

10+ Year Member



hi guys,

i'm creating a site that is for videos. every time i have new videos, it generates a unique video key and that is the url that the video will use or its actual address. i need help how to rename its url to its filename of the video. i guess .htaccess and mod write will do that but i'm a newbie on that process. any help?

sample: http://www.example.com/myfolder/myvideo/view_video.php?viewkey=ebd93369ce542e8f2322&page=1&viewtype=&category=mr
i want to change this to
http://www.example.com/myfolder/myvideo/name-of-the-video-that-is-playing

and based on some threads here. i used .htacces to that code:
RewriteEngine On

Rewritecond %{REQUEST_FILENAME}!-d
RewriteRule ^([-,_0-9a-zA-Z]+)/?$ view_video.php?viewkey=$3 [L]

correct me if i am wrong... Thanks guys.

[edited by: jdMorgan at 2:43 am (utc) on Dec. 4, 2007]
[edit reason] example.com [/edit]

gergoe

12:50 am on Dec 4, 2007 (gmt 0)

10+ Year Member



Almost good;

  • The back references ($# - where # is a number from one to nine) in the replacement string (second parameter of RewriteRule) is counting from one, that's if you have only one bracketed expression in the regular expression (first parameter), you have to use
    $1
    ;
  • The
    [-,_0-9a-zA-Z]
    regular expression is quite complicated compared to what you need, I'd suggest to make it only
    [0-9a-z]
    and make the RewriteRule case insensitive (NC modifier);
  • The RewriteCond is not really necessary, as it is not very likely that you have filenames without . (dot), and as long as it is true, the RewriteRule will not match anything else but the videos. Even if you have something that might match this regular expression, I'd suggest to avoid the use of file checks, as it is costing resources, a simple RewriteCond with a regular expression would serve better.

So assuming you place this into a .htaccess file in the /myfolder/myvideo/ directory of your website, the following should do the trick:

Options +FollowSymlinks 
RewriteEngine On
RewriteRule ^([0-9a-z]+)/?$ view_video.php?viewkey=$1 [NC,L]

bheewhay

2:36 am on Dec 4, 2007 (gmt 0)

10+ Year Member



thanks...
i just do that in an .htaccess and upload it in the directory but still, not working...

what is the output of that rewriteRule that you gave to me... thanks... and can you give me more example like... this code, have this output like that thanks...

gergoe

12:32 pm on Dec 4, 2007 (gmt 0)

10+ Year Member



This rule is supposed to rewrite urls like /myfolder/myvideo/ebd93369ce542e8f2322 into /myfolder/myvideo/view_video.php?viewkey=ebd93369ce542e8f2322, as it would do with any other string which contains only alphanumeric characters.

Did you checked that the use of the .htaccess files are enabled after all? For more infromation on the .htaccess file and the mod_rewrite see Apache Tutorial: .htaccess files [httpd.apache.org] and URL Rewriting Guide [httpd.apache.org].