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

标签 .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?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]

最佳答案

将此代码替换为 .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]

关于.htaccess - 如何使用 php 在我的目录中创建友好的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18658747/

相关文章:

php - 仅 .html 的漂亮网址

.htaccess - 使用 htaccess 禁用除一个文件夹之外的所有目录列表?

Mod-Rewrite "Canonical URL' s”

apache - 如何在一个 .htaccess 文件中编写多个重写条件和规则以重定向 url?

Angular 无法加载其他路线

c# - ASP.NET C# SEO 用于我的电子商务网站详细信息页面上的每个产品

php - 如何重定向 https ://to https://www on . htaccess 文件?

javascript - 通过 .htaccess 添加文件以指定标签

seo - HTML 搜索引擎优化 : Why my page identified as two different pages

.htaccess RewriteRule 用于处理隐藏和可见的 GET