简体   繁体   English

使用.htaccess中的URL重写隐藏GET参数

[英]Hide GET parameters with url rewriting in .htaccess

I know this type of questions was already asked and answered, I've tried several ways to do it, but I can't make it work. 我知道这类问题已经问过并回答了,我已经尝试了几种方法来解决,但我无法解决。 So I access to a page where I've a list of products and a pagination, for the moment to change the page the url is like that : 因此,我访问了一个页面,其中有一个产品列表和一个分页,现在要更改页面的网址是这样的:

domain.com/brands?p=2

and I would like access it like that : 我想这样访问它:

domain.com/brands/2

The last way i tried was this one : 我尝试的最后一种方法是:

RewriteRule ^brands/([0-9]*)$ brands?p=$1 [L]

but when I try to access to the page I get a 404 error. 但是当我尝试访问该页面时,出现404错误。

So is there a mistake ? 那有个错误吗? Or the problem is located somewhere else ? 还是问题出在其他地方? Like another url rewriting which interferes with this one .. 就像另一种URL重写会干扰它一样..

这是您可以应用的示例:

Rewriterule ^post/([0-9]+)/?$ /blog.php?id_blogs=$1

You can try this one: 您可以尝试以下一种方法:

RewriteCond %{THE_REQUEST} /brands\.php\?p=([^\s&]+) [NC]
RewriteRule ^ brands/%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^brands/([^/]+)/?$ index.php?p=$1 [L,QSA,NC]

make sure to ON the RewriteEngine using 确保使用以下命令打开RewriteEngine

RewriteEngine on

Use following code to hide get parameters 使用以下代码隐藏获取参数

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/(.*)/$ /blog.php?slug=$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM