views:

37

answers:

1

I wish to redirect all page requests if

(1) Current URL doesn't have .php extension

(2) Current Page is not the Site Home (ie www.site.com )

Example:

http://site.com/robin to profile.php?screen_name=robin

Can someone suggests the htaccess to accomplish this?

A: 

This site should give some hints:

http://www.webweaver.nu/html-tips/web-redirection.shtml

an excerpt from there:

Changed file extension?

This example is perfect if you've decided to switch to .php from .html pages. It will look for any .html page and redirect it to .php (ie http://www.example.com/yourpage.html and redirect it to http://www.example.com/yourpage.php). Now, be careful with this, it does mean any html page. I did this on one of my sites and had totally forgotten I had an iframe with .html content on some pages... I didn't notice for weeks that it was broken :S. So learn from my mistake ;-) check, double check, then check again.

RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php

You can put arbitrary regular expressions as parameter to Redirectmatch, so you need to add a regular expression which matches '".php" not last of line'. I am only a neophyte of RegExes myelf, so i do not provide an example yet. Check for a later update -have to do some experimating.

sum1stolemyname
I need htaccess that redirects when .php is NOT PRESENT in the url..
dremay
Another condition is, the current page is not the site index page.. Because index page may somewhere doesn't have .php extension (www.site.com)
dremay