Can explain me why this rule not working.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule \/get-info\/plugin\/(.*) \/repositories\/get-info.php?plugin=$1
I want when someone access to:
www.example/get-info/plugin/test
go to:
www.example/repositories/get-info.php?plugin=test
Can explain me why this rule not working.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule \/get-info\/plugin\/(.*) \/repositories\/get-info.php?plugin=$1
I want when someone access to:
www.example/get-info/plugin/test
go to:
www.example/repositories/get-info.php?plugin=test
Share
Improve this question
edited Mar 19 at 15:58
MrWhite
46.1k8 gold badges64 silver badges88 bronze badges
asked Mar 17 at 13:24
pedrofernandespedrofernandes
16.9k10 gold badges37 silver badges44 bronze badges
3
|
1 Answer
Reset to default 1Your current .htaccess
rule isn’t working because:
Incorrect Escaping of Slashes
You don't need to escape slashes (/
) inRewriteRule
. Apache processes them as normal characters.Missing Start Anchor (
^
)
In.htaccess
, the URL path being matched never starts with a leading slash. Your rule should start with^
to properly match from the beginning.Recommended Fix
Try this corrected rule:Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteRule ^get-info/plugin/(.*)$ repositories/get-info.php?plugin=$1 [L,QSA]
Explanation:
^get-info/plugin/(.*)$
→ Matches/get-info/plugin/anything
correctly.repositories/get-info.php?plugin=$1
→ Redirects to the correct script.[L,QSA]
:L (Last) → Stops processing further rules if this one matches.
QSA (Query String Append) → Ensures existing query parameters aren’t lost.
This should correctly rewrite www.example/get-info/plugin/test
to www.example/repositories/get-info.php?plugin=test
.
RewriteRule ^/?get-info/plugin/(.*) /repositories/get-info.php?plugin=$1
with an optional slash at the start for a rule that will work in both .htaccess as well as in server config/vhost. – C3roe Commented Mar 17 at 13:30