Luke
Luke

Reputation: 3046

force pages to end in a slash and rewrite the url

i have to call my pages in this way:

http://example.com/index.php?page=homepage

i want to always show the url in this way

http://example.com/homepage

and at the same time i also want to prevent the insertion of the / at the end of the url...so:

http://example.com/homepage/ or http://example.com/homepage

point to the same page. how can i do this trick with htacces? have i to correct all relative path of files in my html?

thanks a lot

Upvotes: 0

Views: 226

Answers (2)

LazyOne
LazyOne

Reputation: 165343

# activate Rewrite Engine
RewriteEngine On
# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# remove trailing slash
RewriteRule ^(.+)/$ $1 [R=301,L,QSA]
# rewrite all other requests to index.php
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

Upvotes: 1

planestepper
planestepper

Reputation: 3317

RewriteEngine on
RewriteBase /
RewriteRule ^(css|js)/(.*)?$ $1/$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
RewriteRule ^(.*)/$ $1 [R]

Last update from this.

Upvotes: 0

Related Questions