0

I swear am not able to get this, i read 10 tutorials but unable to make it work...I wanted pretty urls so my directory structure goes like this

localhost/my_website/home.php?page=dashboard

I have an .htaccess file in my_website folder with these rules

#Redirect To Default Login Page
DirectoryIndex login.php

#Block Directory Listing
IndexIgnore * 

# Turn on URL rewriting
RewriteEngine On

RewriteRule ^page/([^/\.]+)/?$ home.php?page=$1 [L]

But when I type this http://localhost/my_website/home/dashboard I actually do not get anything

What I get is

The requested URL /my_website/home/dashboard was not found on this server.
Random Guy
  • 2,878
  • 5
  • 20
  • 32

2 Answers2

1

You may try this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^/]+)/([^/]+)$ [NC]
RewriteRule .*  my_website/%1.php?page=%2 [L,QSA]

It will map silently:

http://localhost/my_website/anything1/anything2

To:

http://localhost/my_website/anything1.php?page=anything2

I assumed home and dashboard in the question are variables (Can be anything).

Felipe Alameda A
  • 11,791
  • 3
  • 29
  • 37
  • @Yassine Houssni I know, but that name can be changed tomorrow and it's better than using a fixed string. Same happens with the value of page. – Felipe Alameda A Jan 06 '13 at 13:24
  • ahhh right right, that is indeed way better! thanks for the tip!! –  Jan 06 '13 at 14:37
1

This is what you will need:

 RewriteEngine On
 RewriteRule ^my_website\/home\/([a-z0-9_-]+)?$ my_website/home.php?page=$1 [L]