首页 > 解决方案 > 使用 htaccess 从 url 中删除查询字符串

问题描述

我需要一些有关 htaccess 的帮助。你会好心帮忙吗?我有这样的网址

https://example.com/index.php?p=application-intelligence

[或者]

https://example.com/?p=application-intelligence

基本上 index.php 被传递了一些参数'home' 以知道要加载哪个页面,即 home.php 所以我试图在你的博客上关注你的帖子,但运气不佳。

所以我希望最终的代码是

https://example.com/application-intelligence

这是我的代码。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1

也适用于 https://example.com?p=home

我希望它只是

https://example.com

标签: regexapache.htaccessmod-rewrite

解决方案


这就是我的 apache 虚拟主机 conf 文件中的内容:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

推荐阅读