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

http://localhost/gandalf/play-video.php?vid=video

rather than

http://localhost/mysite/gandalf/play-video.php?vid=video

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…

Update:

I get a 404 as it tries to send me to

http://www.domain.co.uk/services/users/storage/account/www/domain.co.uk/gandalf/play-video.php?vid=video

Url is http://www.domain.co.uk/gandalf/play-video-video

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

/gandalf/play-video.php?

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.

2 Likes

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