URL rewritemap apache

吃可爱长大的小学妹 提交于 2020-01-07 04:30:29

问题


I am pretty new to programming, and have encountered the following problem. Please kindly advise me.

I have a website with a URL like www.mysite.com/products.php?cid=3 where the value of the parameter cid (3 here) is generated from a backend database, and can be a number from 1 to 3.

I would like Apache to rewrite the URL, so that:

www.mysite.com/nike will redirect to www.mysite.com/products.php?cid=1

www.mysite.com/reebok will redirect to www.mysite.com/products.php?cid=2

www.mysite.com/kswiss will redirect to www.mysite.com/products.php?cid=3

etc...

I have a text file named category.txt under the root directory with the following content:

nike 1 
reebok 2 
kwiss 3 

and .htaccess

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 
rewritemap categorymap txt:/image/categorymap.txt 
RewriteRule ^(.*) /products.php?cid=${categorymap:$1|NOTFOUND} [PT] 
</IfModule> 

This, however does not work, please advise me,


回答1:


The RewriteMap directive can only be used in either server or vhost config. You'll need to define it there. If you don't have access to either server or vhost config, then you'll just need to enumerate all of those into individual rewrite directives like:

RewriteRule ^nike$ /products.php?cid=1 [L,QSA]
RewriteRule ^reebok$ /products.php?cid=2 [L,QSA]
RewriteRule ^kswiss$ /products.php?cid=3 [L,QSA]


来源:https://stackoverflow.com/questions/11962196/url-rewritemap-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!