简体   繁体   English

如何使用.htaccess隐藏我的URL参数

[英]How can I hide my URL parameter using .htaccess

So this is my htaccess file as Wordpress supplies it 这是我的htaccess文件,因为Wordpress提供了它

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I have a page at /events, that I want to add a block of text via a template PHP file, depending on if a URL parameter exists. 我在/ events上有一个页面,我想通过模板PHP文件添加一个文本块,具体取决于是否存在URL参数。

So I took a look online, and tried to write an .htaccess rule for it. 因此,我在网上看了一眼,并尝试为其编写.htaccess规则。 What I came up with was this 我想到的是这个

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^events/([^/\.]+)/?$ events/?flow=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

However, I don't think this is working how I'd like it to. 但是,我认为这不符合我的意愿。 The link from the original page is /events?flow=open-evenings and in the events page, I have the usual $_GET thing: 原始页面的链接是/ events?flow = open-evenings,在事件页面中,我通常使用$ _GET东西:

$flow = isset($_GET['flow']) ? $_GET['flow'] : '';
if($flow == 'open-evenings') { echo "blah"; }

But when I try to view the URL /events/open-evenings I get the 404 error page. 但是,当我尝试查看URL / events / open-evenings时,出现了404错误页面。 Have I placed the rule in the wrong place, or am I not doing something obvious? 我是否将规则放置在错误的位置,或者我没有做明显的事情? All help is appreciated! 感谢所有帮助!

Update : this is using Wordpress, so maybe i shouldn't be using the already rewritten urls? 更新 :这是使用Wordpress,所以也许我不应该使用已经重写的URL? Should I be using index.php instead? 我应该改用index.php吗? But will that still pickup the pretty urls that I'm trying to use? 但这是否还会获取我尝试使用的漂亮网址?

I've tried to change the URL to index.php, to try and get that to work, but with the below rule, I'm still getting a 404 page. 我尝试将URL更改为index.php,以尝试使其正常工作,但是按照以下规则,我仍然得到404页面。

RewriteRule ^events/([^/]*)$ /index.php?flow=$1

Can anyone help me try to get this working? 任何人都可以帮助我尝试使其正常工作吗?

This will do the following: 这将执行以下操作:

1>   temp.example.com/save.php?item=xxxxx&id=xxx&type=1 
2>   temp.example.com/save.php?item=xxxxx&id=xxx&type=2 

to be like 像是

1>   temp.example.com/save/xxxxx/xxx
2>   temp.example.com/save/xxxxx/xxx

You can use these rules in root .htaccess: 您可以在根.htaccess中使用以下规则:

RewriteCond %{THE_REQUEST} /save\.php\?item=([^\s&]+)&id=([^\s&]+)&type=([^\s&]+)\s [NC]
RewriteRule ^ save/%1/%2/%3? [R=302,L]

RewriteRule ^save/([\w-]+)/([\w-]+)/([\w-]+)/?$ save.php?item=$1&id=$2&type=$3 [L,QSA,NC]

Let me know if that helps... 让我知道是否有帮助...

Replace the needed values to yours. 将所需的值替换为您的值。 Is this something similar that you need? 您是否需要类似的东西?

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

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