Forum Moderators: phranque

Message Too Old, No Replies

Newbie Mod rewrite Help

php player and mod_rewrite

         

boatmansrq

9:37 pm on Oct 22, 2008 (gmt 0)

10+ Year Member



HI,
I wish to implement a mod_rewrite on the video portion of my website

current urls
[mysite.com...]

wish to change it to
[mysite.com...] (title)

Also need to work on duplicate content issue from video showing up in it's own category as well as in most viewed and all videos

Searched multiple times on multiple forums, trying to learn my way around it. Have had good luck with other rewite and redirect .htaccess files, but this one has me stuck.
Any help or direction to forum posts, read most of the standard stuff, just can't get my head around this one.
Thanks in Advance,
Dave

ag_47

1:21 am on Oct 23, 2008 (gmt 0)

10+ Year Member



You'll also need the category (C) in the URL right? Because I can see it's aparameter for player.php

So to map something like:
mysite.com/videos/105/Boating/Hurricane-Ike-Flyover (title)
to:
mysite.com/videos/player.php?vid=105&C=Boating

You may use:
RewriteRule ^videos/([0-9]+)/([0-9a-z]+)/[0-9a-z\-]+$ /videos/player.php?vid=$1&C=$2 [NC,L]

You don't really need the title part tough right?

boatmansrq

3:57 am on Oct 23, 2008 (gmt 0)

10+ Year Member



To gain the title in the url is the point that I am trying to get to.

ag_47

4:00 am on Oct 23, 2008 (gmt 0)

10+ Year Member



The wrap the title RegEx in brackets and use it as needed:

^videos/([0-9]+)/([0-9a-z]+)/([0-9a-z\-]+)$

$1 -> Id
$2 -> Category
$3 -> Title

g1smd

9:45 am on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



URLs are defined by the stuff in the links on the page.

Mod_Rewrite cannot "change a URL". It connects your URL request (generated from whatever you clicked on) and connects that request to the required internal server filepath.

To get the title into the URL, you need to modify your script so that the script looks at the database and extracts the title and uses that when it is writing out the links on the page.

Mod_Rewrite can then connect that request back to the correct internal filepath. One word of warning: the script will then also need to check that the title requested is correct for that numbered ID, otherwise I could link to you with any words in place of the real title and those alternative URLs would also be indexed and destroy your site with multiple duplicate content issues.

boatmansrq

1:24 pm on Oct 23, 2008 (gmt 0)

10+ Year Member



Understand what your saying, need to build a link factory. Any good tutorials on that available?
Thanks

jdMorgan

1:41 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The solution to this type of problem is generally to call a script, either using a RewriteMap or by rewriting directly to that script, so that the script can be used to access the main database and translate between "internal id numbers" and "SEO-friendly title URLs". Without a RewriteMap, mod_rewrite cannot 'create' the long, SEO-friendly title out of thin air using only the "id number" -- It has no knowledge of the association between the id number and the title unless you provide some kind of associative list or array.

To call a URL-to-filepath translation script using RewriteMap, you must have access to the server config files in order to define that RewriteMap; While RewriteMaps can be used in .htaccess, they must be defined at the server config level (for security reasons). When using a RewriteMap method like this, the server still does most of the content-handling and response code generation.

If you rewrite all appropriate requests directly to a script rather than using RewriteMap, then that script must do all content-handling and provide appropriate and correct server response codes under all conditions. That is, it must translate the requested URL to the appropriate database entry, use that database entry to generate content, and then output all of the server response headers that go with that type of content. If the requested URL does not correspond to a valid database entry, then the script must generate a correct and complete error response.

Jim