How to remove index files from URL on Nginx



  

now i gonna show u guys ,How to remove index files from URL on Nginx









So yesterday while i was idling on Freenode i saw someone asking in Nginx channel that he basically wants to remove the index.php file from the url or in other words he wants to redirect http://www.mydomain.com/index.php into http://www.mydomain.com/ … probably for canonicalization purpose (canonical url) and/or perhaps SEO purpose. He had tried this:
# And it causes redirect loop (also tested on my local box)
# Atlhough it works fine for simple php files but not on his vBulletin setup
# or other non simple php file (because i don't have access to vBulletin i tested it on other script)
# Note the | is for illustration
location =|~ /index.php {
 rewrite ^ http://www.domain.com/|/ permanent;
}
And being curious, i’m doing a test on my local box to remove that index.php thing from the URL and found a way to do it and it was simple. So if you’re currently looking for a way to remove or redirect your index file from the URL and you’re using Nginx perhaps this simple tips can help you with that
First thing first is open your nginx configuration files that hold your virtual hosts configuration and then add this line inside the server directive:
# This will redirect index.php index.htm to /
# Feel free to add other extension you need
if ( $request_uri ~ "/index.(php|html?)" ) {
 rewrite ^ / permanent;
}
And an example just in case you want to see where it should be placed
server {

 [...] # other stuff such as server_name, access_log, etc

 # Here goes the code
 if ( $request_uri ~ "/index.(php|html?)" ) {
  rewrite ^ / permanent;
 }

 location / {
  [...] # your root configuration
 }

 location ~ "\.php$" {
  [...] # your fastcgi configuration
 }

}
Then reload your nginx configuration. Now every request for index.php or index.html or index.htm file will be displayed as http://www.mydomain.com/. And if there’s a query string in your URL it’ll be displayed as http://www.mydomain.com/?q=abc instead of http://www.mydomain.com/index.php?q=abc







make sure man,that the sites are sertified and it's terms and conditions.
coz we dont wanna make any trouble.! that'all.
the above codes are not violating any of the terms and conditions
that for the secure of the internet users.
so please go on!.








no video for this stuff

Latest posts.