简体   繁体   中英

Apache mod_rewrite REST URL

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!

Try putting this in your server/vhost config or the htaccess file in your document root:

RewriteEngine On

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

RewriteCond %{QUERY_STRING} ^(.*),(.*)$
RewriteRule ^/?serivce/ca\.php$ /service/ca.php?%1&%2 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM