.htaccess RewriteEngine多个页面相同的代码

时间:2013-11-03 12:48:15

标签: .htaccess

我想通过RewriteEngine获取此信息:

mysite.com/translate/hola    referring to mysite.com/?goTo=translate&str=hola
mysite.com/buy/12            referring to mysite.com/?goTo=buy&id=12

如何使用一条规则执行此操作? 感谢

1 个答案:

答案 0 :(得分:0)

启用mod_rewrite.htaccesshttpd.conf(如果尚未启用),然后将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

ewriteCond %{REQUEST_FILENAME} !-f
ewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?goTo=$1&id=$2 [L,QSA]

参考:Apache mod_rewrite Introduction