Mod_Rewrite with path redirection
I have this rule in a .htaccess file located in a directory named clips/
:
RewriteRule ^mlk/?$ segment/index.php?clip=1 [R=301,QSA,L]
I intend that when someone visits http://example.local/clips/mlk
they are redirected tohttp://example.local/clips/segment/index.php?clip=1
What actually happens is that when someone visits example.local/clips/mlk
they are redirected toexample.local/var/www/example/clips/segment/index.php?clip=1
I'm not sure why he does this. If I change the rewrite rule to this:
RewriteRule ^mlk/?$ /segment/index.php?clip=1 [R=301,QSA,L]
Is the user redirected to example.local / segment / index.php? clip = 1, which is still wrong. I don't want to give an absolute path in case these files are navigated through the directory tree of the website. How can I make this work relatively and not absolutely?
source to share
Try to add RewriteBase directive like below
RewriteEngine On
RewriteBase /clips/
RewriteRule ^mlk/?$ segment/index.php?clip=1 [R=301,QSA,L]
EDIT
but is there a way to make this work without using the RewriteBase directive
You can also try
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(/[^/]+/) [NC]
RewriteRule ^mlk/?$ http://%{HTTP_HOST}%1segment/index.php?clip=1 [R=301,QSA,L]
source to share