.htaccess 如何使用php在我的目录中创建友好的url

.htaccess 如何使用php在我的目录中创建友好的url,.htaccess,url-rewriting,seo,.htaccess,Url Rewriting,Seo,我使用以下类型的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?rques

我使用以下类型的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]
这应该可以解决这个问题:

RewriteEngine On
RewriteRule ^rest/api.php?action=test$ /rest/api/action/test [L]
这应该可以解决这个问题:

RewriteEngine On
RewriteRule ^rest/api.php?action=test$ /rest/api/action/test [L]

通过将您的代码与
文档根/rest
目录下的
.htaccess
关联,将此代码放入:

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]

通过将您的代码与
文档根/rest
目录下的
.htaccess
关联,将此代码放入:

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]

可以通过使用以下语法的正则表达式来实现您的目标:

RewriteRule ^rest/api/action/(\d+)*$ ./rest/api.php?action=$1 
尝试阅读以下文章:


您可以通过使用以下语法的正则表达式来实现目标:

RewriteRule ^rest/api/action/(\d+)*$ ./rest/api.php?action=$1 
尝试阅读以下文章:


RewriteRule
与查询字符串不匹配。
RewriteRule
与查询字符串不匹配。