video/watch.php?pid=320 --> watch:320

New to mod_rewrite? This is a good place to start.

video/watch.php?pid=320 --> watch:320

Postby nypd » Thu Oct 18, 2007 8:13 am

I was wondering how to do it.

have tryed this:

RewriteRule ^watch:?(.+)$ /watch.php?pid=$1 [NC]
but it wont work

Also i have read this:
viewtopic.php?t=4221&highlight=file+rewrite
but not success, or i have not understand it...
nypd
 
Posts: 48
Joined: Wed Aug 01, 2007 2:20 am

Postby richardk » Thu Oct 18, 2007 1:04 pm

What happens when you go to /watch:123? Test you have mod_rewrite available.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^watch:([0-9]+)$ /watch.php?pid=$1 [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nypd » Fri Oct 19, 2007 9:39 am

when i try your solution:

/video/watch:3124 was not found on this server.
nypd
 
Posts: 48
Joined: Wed Aug 01, 2007 2:20 am

Postby richardk » Fri Oct 19, 2007 10:01 am

Where are you putting the .htaccess file? If it's in /video, add a "." in front of "/watch.php". If it's in your document root, add "/video" in front of "/watch.php" and "video/" after "^".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nypd » Fri Oct 19, 2007 11:42 pm

still no luck The .htaccess file is in the root. However i got this in it (conserning video)

Code: Select all
RewriteRule ^video$ /video/$1 [R]^
RewriteRule ^video/?(.+)$ /wraps/video/$1 [NC]^
RewriteRule ^video?(.+)$ /wraps/video/$1 [NC]^


This works:

RewriteRule ^watch:?(.+)$ /wraps/video/watch.php?pid=$1 [NC]

in browser it is domain.com/watch:ID
however i want it to be domain.com/video/ID

Just to rewrite the watch part....
nypd
 
Posts: 48
Joined: Wed Aug 01, 2007 2:20 am

Postby richardk » Sat Oct 20, 2007 4:30 pm

So you want /watch/<something> to go to /wraps/video/watch.php?pid=<something>? Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^watch/([^/]+)/?$ /wraps/video/watch.php?pid=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nypd » Sat Oct 20, 2007 9:48 pm

thank you, richardk. yes, your suggestion works just fine. However what i need is just watch.php rewrite. nothing else.

i need

domain.com/video/ID to go to
domain.com/video/watch.php?pid=ID

in other words the rewrite i need is to replase the watch.php?pid=ID
with just an ID.

now i have 1 rewrite conserning video already in my htaccess file (which is in the root):

Code: Select all
RewriteRule ^video$ /video/$1 [R]^
RewriteRule ^video/?(.+)$ /wraps/video/$1 [NC]^
RewriteRule ^video?(.+)$ /wraps/video/$1 [NC]^


hope it does not interfiere in some way. Actoually it does when i try to replace the /watch/ID part with /video/ID and that is normal. That is why i wonder can i just rewrite the file name (everything after the video last slash)

P.S. I understand that this is a bit different from the start topic. Probably i should open new thread called

/watch.php?pid=ID -> /watch/ID
nypd
 
Posts: 48
Joined: Wed Aug 01, 2007 2:20 am

Postby richardk » Sun Oct 21, 2007 2:26 pm

Try the following in a .htaccess file in your document root (you do not need those other rules)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?pid=([^&]+)(&.*)?$ [NC]
RewriteRule ^wraps/video/watch\.php$ /watch/%2/? [R=301,L]

RewriteRule ^watch/([^/]+)/?$ /wraps/video/watch.php?pid=$1 [QSA,L]

You still need to edit the URLs in your pages, though.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nypd » Tue Oct 23, 2007 12:49 am

That works just fine. richardk, you have been most helpfull. Thank you very very much. One last question though...


How 'bout this:
/watch.php?pid=ID -> /ID

Icv i manage to do it, then i will not need to edit the other urls that depend on the video directory.

so that the final result to be:
Code: Select all
domain.com/video/ID


instead of:
Code: Select all
domain.com/video/watch.php?pid=ID
nypd
 
Posts: 48
Joined: Wed Aug 01, 2007 2:20 am

Postby richardk » Tue Oct 23, 2007 2:10 pm

You should, if you don't edit the URLs every link clicked will result in two requests to the server making a lot of pointless traffic.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron