RewriteRule confusion

I have the following rule in my .htaccess file. It works fine on my live site but on my localhost it sends me to


rather than


RewriteRule ^gandalf/play-video-([A-Za-z0-9-\']+)$ /gandalf/play-video.php?vid=$1 [R=302,L]

Can the rule be changed to work on both the live site and localhost? I’ve tried removing the leading slash on the target but that doesn’t work (I forget what it does! :blush: )

Doesn’t it mean, as normally, “from the root directory” of the site?

It is a plain url isn’t it? :thinking:

Hold on, I’ll try it and tell you what happens…


I get a 404 as it tries to send me to

Url is

That’s pretty amazing for a leading slash in the target: :smiley:


Does your .host file have the correct virtual site?

1 Like

That’s without the slash. With the slash works.

1 Like

Variant 1.

RewriteRule ^(([A-Za-z0-9-']+)\/)?gandalf/play-video-([A-Za-z0-9-']+)$ /$1gandalf/play-video.php?vid=$3 [R=302,L]

Variant 2.

Create virtual host with root directory mysite. Then you need no changes in .htaccess.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.