.htaccess - Two rewrites to the same location

Soldato
Joined
27 Dec 2005
Posts
17,296
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
 

daz

daz

Soldato
Joined
18 Oct 2002
Posts
24,079
Location
Bucks
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.
 
Associate
Joined
21 May 2013
Posts
1,991
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