Darren Parker
Darren Parker

Reputation: 71

Re-route all requests to index.php with request as query string (.htaccess)

I'm writing my very first .htaccess file and although I've learnt a lot already I have one thing that I'm struggling with.

I have a CMS that generates pages based upon a variable called "filename" that's passed through my URL for example... index.php?filename=about.htm

So I only have one real file... index.php

I would like "index.php?filename" to not appear so all URL's look normal like www.example.com/about.htm even though the "filename" query string is still being passed.

I hope I've made sense and this is possible... Thanks guys!

Upvotes: 2

Views: 782

Answers (2)

Want to rewrite /$var to /index.php?filename=$var? Try to paste this into the .htaccess file:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} filename=([a-z0-9-_])
RewriteRule ^(.*) /index.php?filename=%1

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143946

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?filename=$1 [L,QSA]

Upvotes: 0

Related Questions