0

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

Luke
  • 2,976
  • 6
  • 34
  • 44

2 Answers2

1
# 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]
LazyOne
  • 158,824
  • 45
  • 388
  • 391
0
RewriteEngine on
RewriteBase /
RewriteRule ^(css|js)/(.*)?$ $1/$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
RewriteRule ^(.*)/$ $1 [R]

Last update from this.

Community
  • 1
  • 1
planestepper
  • 3,277
  • 26
  • 38
  • i had to add RewriteBase /example.com/ to make it work, thanks. but now when i call every css or js, they're just replaced with the content of the page. how can i avoid it? – Luke Jun 26 '11 at 22:12
  • @1uc4 do you have your js and css on the same folder as your pages? I would assume not – planestepper Jun 26 '11 at 22:14
  • @leon yes, now it works perfectly when i call example.com/homepage. but when i call example.com/homepage/ everything is searched in example.com/homepage/css or example.com/homepage/js – Luke Jun 26 '11 at 22:30
  • @1uc4 trying again - pls check – planestepper Jun 26 '11 at 23:43