在 URL 重写不起作用的情况下删除查询参数 [英] Remove query param with URL Rewriting not working

查看:42
本文介绍了在 URL 重写不起作用的情况下删除查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用包含的参数重写 URL,如下所示:https://mywebsite/FOF/news/page/page1.php?name=petter&country=usa

I'm trying to rewrite the URL's with params contained looks like: https://mywebsite/FOF/news/page/page1.php?name=petter&country=usa

我认为它不像 url 那样美观,我希望它看起来更像这样:

I think it's not very aesthetic as url and I would like it to look more like this:

https://mywebsite/spiderman

https://mywebsite/spiderman

实际上是重写工作并给我这个结果https://mywebsite/spiderman?name=petter&country=usa 直到 https://mywebsite/spiderman

Actually the rewrite work and give me this result https://mywebsite/spiderman?name=petter&country=usa until https://mywebsite/spiderman

这是我的重定向规则

##Enabling FollowSymlinks and disabling MultiViews options here.
Options +FollowSymlinks -MultiViews
##Setting rewrite base to / here.
RewriteBase /
RewriteEngine on
##Rewriting for page1 uri here.
RewriteRule ^page1$ page1.php    
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\s [NC]
RewriteRule ^ /customPage? [R=301,L]

##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customPage/?$ FOF/news/page/page1.php [L,NC]

如果有人可以帮助我

推荐答案

使用您展示的示例,尝试;请尝试遵循 htaccess 规则.其中 customPage 是您要在浏览器上重定向的页面(您显示的问题中的蜘蛛侠).这是针对您显示的示例的特定页面请求.

With your shown samples, attempts; please try following htaccess Rules. Where customPage is the page which you want to redirect on browser(spiderman in your shown question). This is for specific page request as per your shown samples.

确保在测试您的 URL 之前清除浏览器缓存.

Make sure to clear your browser cache before testing your URLs.

##Enabling FollowSymlinks and disabling MultiViews options here.
Options +FollowSymlinks -MultiViews
##Setting rewrite base to / here.
RewriteBase /
RewriteEngine on
##Rewriting for page1 uri here.
RewriteRule ^page1$ page1.php    
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\?name=(?:[^&]*)&country=(?:\S+)\s [NC]
RewriteRule ^ /customPage? [R=301,L]

##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customPage/?$ FOF/news/page/page1.php?name=petter&country=usa  [L,NC,QSA]

这篇关于在 URL 重写不起作用的情况下删除查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆