Panama Jack
Panama Jack

Reputation: 24468

mod_rewrite with ? in the original URL like YouTube

Ok I want to simulate the YouTube URL and redirect it to my real URL. Reason being is I used a random string to make video ID's so they aren't guessable by sequence. I have the links as so

http://www.mysite.com/watch?v=Dxdotx3iT1

and want to redirect to

http://www.mysite.com/index.php?page=videos&section=view&v=Dxdotx3iT1

Can't seem to figure out the mod rewrite. Also using a ? I believe tells it to do something.

Any help would be appreciated.

Upvotes: 1

Views: 573

Answers (3)

user13611442
user13611442

Reputation: 1

None of these answers worked for me, so in the end I found through trial and error the following worked for me;

The RewriteRule to get my URL to look like this https://www.example.com/video/watch?v=UnIq3Id follows;

RewriteRule ^video\/watch\?*$ index.php?page=video [L,QSA]

I found that the following rule I had previously set up to make my URL look like this https://www.example.com/video/UnIq3Id interfered with my redirecting;

RewriteRule ^/?([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ index.php?page=$1&v=$2 

Simply commenting it out fixed the issue, as follows;

#RewriteRule ^/?([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ index.php?page=$1&v=$2

The RewriteRule to get my URL to look like this https://www.example.com/watch?v=UnIq3Id is as follows;

RewriteRule ^watch\?*$ index.php?page=video [L,QSA]

I found that the following rule I had previously set up to make my URL look like this https://www.example.com/video/ interfered with my redirecting;

RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?page=$1 [NC]

Simply commenting it out fixed the issue, as follows;

#RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?page=$1 [NC]

Hope it helped someone and saved you the headache I had, people are not so forthcoming on this issue at times How do you write an htaccess RewriteRule to make my urls work like youtube?.

Upvotes: 0

Brandon0
Brandon0

Reputation: 266

RewriteCond %{QUERY_STRING} ^v=(.+)
RewriteRule ^watch /index\.php?page=videos&section=view&v=%1 [QSA,R=301,L]

Upvotes: 0

ceejayoz
ceejayoz

Reputation: 180065

You need to adjust your RewriteRule to include the query string using the [QSA] (query string attached) flag:

RewriteRule ^watch$ index.php?page=video&section=view [QSA]

Upvotes: 4

Related Questions