I'm trying do following rewrite from last two days.
- Force to use www.example.com - done
- Hide PHP extension - done but not sure that it's a good way
- 404 error to custom page - done
Now my main problem is
4. Host all page on root(/)
I have following files:
news.php
search.php
store.php
allstores.php
Client requests like this:
Type 1: http://www.example.com/news
Type 2: http://www.example.com/search?q=term
Type 3: http://www.example.com/allstores/H
Type 4: http://www.example.com/myname
I want to handle these client request like this:
Type 1: http://www.example.com/news ---rewrite to (add extension)-->news.php
Type 2: http://www.example.com/search?q=term ---->No change, Let it same
Type 3: http://www.example.com/allstores/H --rewrite to --->http://www.example.com/allstores.php?ln=H
Type 4: http://www.example.com/myname ---rewrite to------> http://www.example.com/store?st=myname
I have tried following rewrites:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^(.*) store.php?st=$1 [L]
RewriteRule ^allstores/(.*)$ allstores.php?ln=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L]
ErrorDocument 404 /404.php
Any help is highly appreciable, Thank you