1

Please help me with this one, which should be easy but I've never managed to properly learn Apache mod_rewrite's syntax...

I have a REST webservice implemented in PHP and I need to rewrite the following URL:

[1] http://www.myserver.com/service/ca;x={valx},y={valy},z={valz}

into

[2] http://www.myserver.com/service/ca.php?x={valx}&y={valy}&z={valz}

How to accomplish this?

I'm using Apache2 on Ubuntu, this is the configuration:

Alias "/service" "/opt/htdocs/service"
<Directory "/opt/htdocs/service">
  AllowOverride All
  Options -Indexes FollowSymLinks
</Directory>

and the content of my /opt/htdocs/service directory:

$>ls -1 /opt/htdocs/service

  ca.php

Mod_rewrite is enabled:

$>a2enmod rewrite

  Module rewrite already enabled

Thanks in advance!

4

1 回答 1

1

尝试将其放入您的服务器/虚拟主机配置或文档根目录中的 htaccess 文件中:

RewriteEngine On

RewriteRule ^/?service/ca;(.*)$ /service/ca.php?$1 [L]

RewriteCond %{QUERY_STRING} ^(.*),(.*)$
RewriteRule ^/?serivce/ca\.php$ /service/ca.php?%1&%2 [L]
于 2012-10-14T06:38:12.300 回答