Skip to main content

How to run a file without extension as php

Comments

9 comments

  • nixuser
    I generally want to know if this is possible and if possible, how to do this.

    an htaccess rewriterule should work, like: RewriteRule ^([^\.]+)$ $1.php [NC,L]
    can't use the .htaccess code like Options +Multiviews.

    why?
    0
  • Rajeeva Lochana
    I don't want users to access search.php, I only want them to access the file 'search', whereas multiviews allows access to users to search.php (with the php extension also).
    0
  • nixuser
    You want the users to see site.com/search instead of site.com/search.php?
    0
  • Rajeeva Lochana
    yes
    0
  • Rajeeva Lochana
    no access to search.php with the php extension
    0
  • nixuser
    A rewrite rule like the one below should work. RewriteRule ^([^\.]+)$ $1.php [NC,L]
    0
  • cPanelMichael
    Hello @rajeevacj, Let us know if the Mod_Rewrite rule suggestion helps. Thanks!
    0
  • Rajeeva Lochana
    I am sorry for late reply, a glass of water spill on my laptop when I was to reply, so I needed some time to get it work. I fixed the issue myself. The code is the same, but it points to a single file i.e. search.php. .htaccess RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule search search.php [L]
    search.php (at the top of the file) [PHP] == "/search") { } else { header("HTTP/1.1 404 Not Found"); exit(); } ?>[/PHP] I fixed it :)
    0
  • nixuser
    Glad that you have fixed it.
    0

Please sign in to leave a comment.