Question

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.
Was it helpful?

Solution

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).

OTHER TIPS

This is what you will need:

 RewriteEngine On
 RewriteRule ^my_website\/home\/([a-z0-9_-]+)?$ my_website/home.php?page=$1 [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top