开发者

.htaccess Rewrite URLs - RewriteMap

I have the following RewriteMap function:

RewriteMap map_company txt:/var/www/vhost/domain.com/httpdocs/map_company.txt

I am trying to rewrite my index.php?shop_id=1 to /company-name/

so my map_company.txt开发者_开发知识库 file contains: company-name 1

I cannot seem to get it working. Here is my htaccess file:

# tried this
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?shop_id=${map_company:$1} [NC,L,QSA]

#and this
RewriteRule ^(\d+)/$ index.php?shop_id=${map_company:$1} [NC,L,QSA]

If I do that then I get the error: File does not exist: /var/www/vhosts/domain.com/httpdocs/company-name

Does anyone have any ideas? I also need to make sure it doesn't affect my standard folders like "css, js, images".


Have you turned on the rewrite engine? RewriteEngine on needs to be defined. Also, check you have the necessary AllowOverride value for this folder to let you do this.

As an aside, I'd consider making the trailing slash optional:

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?shop_id=${map_company:$1} [NC,L,QSA]


Looks like you can't declare a RewriteMap in an .htaccess file:

The RewriteMap directive may not be used in sections or .htaccess files. You must declare the map in server or virtualhost context. You may use the map, once created, in your RewriteRule and RewriteCond directives in those scopes. You just can't declare it in those scopes.

https://httpd.apache.org/docs/2.4/rewrite/rewritemap.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜