How can I hide my URL parameter using .htaccess

So this is my htaccess file as WordPress supplies it

# 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.

Read More

So I took a look online, and tried to write an .htaccess rule for it. 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:

$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. 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? Should I be using index.php instead? 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.

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

Can anyone help me try to get this working?

Related posts

1 comment

  1. 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:

    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?

Comments are closed.