我使用这些类型的网址:
http://test.com/rest/api.php?action=test
但我需要这些类型的网址:
http://test.com/rest/api/action/test
我尝试.htaccess
在这里提交这些代码
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
答案 0 :(得分:1)
通过将您的代码与.htaccess
目录下的DOCUMENT_ROOT/rest
相关联来放置此代码:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /rest/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/([^/]+)/?$ api.php?action=$1 [QSA,NC,L]
答案 1 :(得分:0)
这应该解决它:
RewriteEngine On
RewriteRule ^rest/api.php?action=test$ /rest/api/action/test [L]
答案 2 :(得分:0)
您的目标可以通过使用语法如下的正则表达式来实现:
RewriteRule ^rest/api/action/(\d+)*$ ./rest/api.php?action=$1
尝试阅读这些文章:
http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/和 http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/