In this set of rules, looks like the requests are considered to always be files and if the request file name is not a file, then it adds .php
to it. It is not always the case though. In apache 2.2 mode_rewrite
REQUEST_FILENAME : The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI
Therefore, the REQUEST_FILENAME may be resolved to files, folders or directories
(this may vary in other web services or other apache versions). In case of files the rules work otherwise it fails. For example //domain.com
will be resolved to the document root. But //domain.com/index.php
will be resolved to the index.php file in the document root. To avoid these kind of confusions, all three possibilities should be considered, generally speaking. Also the REQUEST_FILENAME
may be a file by itself without .php like //domain.com/my_styles.css
. In that case the rules fail too.
Following set of rules should work
RewriteEngine On
RewriteBase /insta/member/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+insta/member/pages/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^insta/member/pages)^(.*)$ /insta/member/pages/$1 [L,NC]
Edit:
Explanation for first set of rules is that it is checking if the resolved filename part of the request is not a directory, link or file and "filename.php" is a file and it is not ending with forward slash then add .php to the request.
Answering to the question in comment about pretty url:
To achieve pretty url you need to know the application routing. For removing a GET parameter from query string like ?checking=value
rule should be like following
RewriteRule (.*)/checking/(.*)$ $1?checking=$2 [L]
It will be like following to combine with the above rules
RewriteEngine On
RewriteBase /insta/member/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)/checking/(.*)$ $1\.php?checking=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1\.php [QSA,L]
Then $_GET
values for following examples would be
http://localhost/insta/member/test
array (size=0)
empty
http://localhost/insta/member/test?checking=value
array (size=1)
'checking' => string 'value' (length=5)
http://localhost/insta/member/test/checking/value
array (size=1)
'checking' => string 'value' (length=5)
http://localhost/insta/member/test/checking/value?second=2
array (size=2)
'checking' => string 'value' (length=5)
'second' => string '2' (length=1)
Finally, here is the specific rule for check/ig/value
to check?ig=value
going to check.php?ig=value
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)/(.*)/(.*)$ $1.\php?$2=$3 [QSA,L]
Sample output for GET
http://localhost/insta/member/check/ig/value
array (size=1)
'ig' => string 'value' (length=5)