Ron Bodnar
Ron Bodnar

Reputation: 103

Using a RewriteRule to clean my URLs

My main goal here is to change what users see when they visit my site.

As of now, if I want to navigate my site, it's done as so:

http://ieztech.net/~aeterna/index.php?page=home or http://ieztech.net/~aeterna/index.php?page=contact-us

What I'm trying to accomplish is, when I send a user to my contact page, I want them to be able to go to http://ieztech.net/~aeterna/contact-us/ but actually display what is located at http://ieztech.net/~aeterna/index.php?page=contact-us.

I have tried a lot of variations of RewriteRule but I can't seem to figure this out.

Here is what I'm currently using:

RewriteEngine On

RewriteBase /
RewriteRule ^(.*)$ index.php?page=$1&%{QUERY_STRING} [L]

I have also tried (which I found here):

RewriteEngine On

RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1

and

RewriteEngine On

RewriteRule ^(.*)/$ index.php?page=$1 [L,QSA]

Is there something else I'm missing, or is what I'm trying just not correct?

Upvotes: 0

Views: 24

Answers (1)

bloodyKnuckles
bloodyKnuckles

Reputation: 12079

Does this work?

RewriteBase /~aeterna
RewriteCond %{REQUEST_URI} !index.php [NC]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

Add this condition to prevent rewriting particular files:

RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|pdf|css|js)

Upvotes: 1

Related Questions