.htaccess - Two rewrites to the same location

Soldato
Joined
27 Dec 2005
Posts
17,310
Location
Bristol
I've got a page that displays a YouTube video and we pass the info via the YouTube ID in the URL, for example domain.com/w/BzMLA8YIgG0. It passes through as GET as follows:

Code:
if(isset($_GET['v'])){
$v = $_GET['v'];

The existing rewrite rule is:

Code:
RewriteRule ^w/(.*)$ watch/?v=$1

I also want the following, but it appears they clash as I get a 500 Internal Server Error.

Code:
RewriteRule ^watch/(.*)$ watch/?v=$1
 
I'm pretty sure the last one will generate a redirect loop, hence the 500.

You'll probably need to do a RewriteCond, perhaps check to see if v has been set.
 
Like daz said, you would want something like:

RewriteCond %{REQUEST_URI} !^/watch/\?v=.*

to avoid re-matching the rewritten URL.

At the moment, this is happening:

example.com/watch/test -> example.com/watch/?v=test -> example.com/watch/?v=?v=test ...
 
Back
Top Bottom