Reputation: 85
I'm having a little bit of trouble with my Htaccess file.
RewriteEngine On
RewriteBase /testwebsite/
RewriteRule ^home/?$ index.php
What i'm trying to accomplish is the following: Whenever the client visits localhost/testwebsite/index.php, he must be redirect to the clean url (localhost/testwebsite/home). Whenever the visitor visits localhost/testwebsite/home, he must stay there but the content of index.php will still be shown.
Currently whenever I visit localhost/testwebsite/home, the content of index.php has been shown, but whenever I visit localhost/testwebsite/index.php, the client still see's the "ugly" url.
I looked up information all over the internet but the method of how mod_rewriting works just won't get inside of my head. Help would be appericiated, thank you!
Upvotes: 1
Views: 47
Reputation: 24478
This is what you need to do. You can use this code in your .htaccess.
RewriteEngine On
RewriteBase /testwebsite/
#redirect index.php to the pretty URL
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /testwebsite/index\.php
RewriteRule ^ home? [R=301,L]
#internally rewrite pretty URL to index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/?$ index.php [L]
Upvotes: 1