문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top