[英]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... 请帮助我解决这个问题,这应该很简单,但是我从未设法正确学习Apache mod_rewrite的语法...
I have a REST webservice implemented in PHP and I need to rewrite the following URL: 我有一个用PHP实现的REST Web服务,我需要重写以下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: 我在Ubuntu上使用Apache2,这是配置:
Alias "/service" "/opt/htdocs/service"
<Directory "/opt/htdocs/service">
AllowOverride All
Options -Indexes FollowSymLinks
</Directory>
and the content of my /opt/htdocs/service
directory: 以及我的
/opt/htdocs/service
目录的内容:
$>ls -1 /opt/htdocs/service
ca.php
Mod_rewrite is enabled: Mod_rewrite已启用:
$>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: 尝试将其放在服务器/ vhost配置或文档根目录中的htaccess文件中:
RewriteEngine On
RewriteRule ^/?service/ca;(.*)$ /service/ca.php?$1 [L]
RewriteCond %{QUERY_STRING} ^(.*),(.*)$
RewriteRule ^/?serivce/ca\.php$ /service/ca.php?%1&%2 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.