JonW
JonW

Reputation: 145

.htaccess file hide GET request in URL

I am very new to .htaccess files and may have done mine wrong. I have been gathering snippets of code trying to get done what I want.

This is what I have in my file so far

I read this should be in your .htaccess file

Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase / 

This was added to force a redirect from HTTP to HTTPS

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This was added to remove .php at the end of all the files

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

This was added to remove the showing of /index when the home link was pressed

RewriteCond %{THE_REQUEST} ^.*\/index?\ HTTP/
RewriteRule ^(.*)index\.php?$ "/$1" [R=301,L]

I have tried a lot of ideas I found on both here and other sites from Google. I have had no luck hiding the GET request. Currently, the URL looks like https://mysite.ca/event?id=123 What I would like it to look like is either https://mysite.ca/event/123

This is hosted on Godaddy and it is just a plain PHP site if that makes any difference.

Any ideas would be great!

Upvotes: 0

Views: 329

Answers (1)

Konstantinos
Konstantinos

Reputation: 973

First of all Options +MultiViews already removes .php extension so you don't need:

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]

About your problem try this Rule:

RewriteRule ^event/([0-9]+)?$ event?id=$1 [NC]

Which changes url from example.com/event/<number> to example.com/event?id=<number>

Although, if your site makes infinite redirects then you should change it to:

RewriteRule ^events/([0-9]+)?$ event?id=$1 [NC]

This happens if you have some includes/headers that redirect back to event and creates infinite loop.

Upvotes: 1

Related Questions