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

コードをディレクトリの.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]
于 2013-09-06T13:21:19.067 に答える
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 に答える