1

我使用这些类型的 URL:

http://test.com/rest/api.php?action=test

但我需要这些类型的 URL:

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]
4

3 回答 3

1

通过将代码替换为您.htaccessDOCUMENT_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]
于 2013-09-06T13:21:19.067 回答
0

这应该解决它:

RewriteEngine On
RewriteRule ^rest/api.php?action=test$ /rest/api/action/test [L]
于 2013-09-06T13:16:51.180 回答
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 -文件/

于 2013-09-06T13:28:56.877 回答