How do I rewrite the below...
There's possibly a more fundamental problem here. You don't rewrite it that way round in .htaccess
. You rewrite from the "friend" URL back to the actual URL/filesystem path. So, it's the other way round, you rewrite from:
http://example.com/local/vendor/Company
to the actual URL your application is expecting:
http://example.com/local/vendor/index.php?handle=Company
For Example:
RewriteEngine On
RewriteRule ^(local/vendor)/(Company)$ /$1/index.php?handle=$2 [L]
$1
and $2
are backreferences to the captured groups in the RewriteRule
pattern.
The above matches just the specific URL you stated, ie. /local/vendor/Company
. I suspect that "Company" is intended to be a placeholder? In which case you need to make this more general. For example:
RewriteRule ^(local/vendor)/(\w+)$ /$1/index.php?handle=$2 [L]
\w
is a shorthand character class for word characters. This excludes the dot (ie. .
) so avoids a rewrite loop when rewriting to index.php
.
UPDATE: The above assumes your .htaccess
file is located in the document root, ie. example.com/.htaccess
. However, if the .htaccess
file is located in the /local
subdirectory (ie. example.com/local/.htaccess
) - as you appear to suggest in comments - then you will need to adjust the above directives to remove local/
from the RewriteRule
pattern and remove the slash prefix from the substitution. For example:
RewriteRule ^(vendor)/(\w+)$ $1/index.php?handle=$2 [L]