-2

My URLs like http://example.com/login.php and i want its shows like http://example.com/login In my website first page is login.php rather than index so i have set this option in .htaccess

Here is .htaccess file code

ErrorDocument 403 403.php
ErrorDocument 404 404.php
ErrorDocument 405 405.php
ErrorDocument 501 501.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ login.php [NC,L]
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)
RewriteRule .* - [R=501,L]


Options -Indexes
DirectoryIndex login.php

<LimitExcept GET POST>
deny from all
</LimitExcept>
ServerSignature Off 
FileETag None
<IfModule mod_reqtimeout.so>
  RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
</IfModule>



    Header set X-FRAME-OPTIONS SAMEORIGIN 
    Header set Content-Security-Policy: "child-src 'self' allow 'self'; media-src *; img-src *; "
    Header set Access-Control-Allow-Origin: "*"
    Header set X-XSS-Protection "1; mode=block"
    Header set Referrer-Policy "no-referrer | same-origin | origin | strict-origin | no-origin-when-downgrading"
    Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
sumit kundan
  • 163
  • 2
  • 11
  • 4
    Possible duplicate of [Remove .php extension with .htaccess](https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – Carl Binalla Jul 17 '19 at 10:16
  • no i have another case also where i have to set first page is login.php – sumit kundan Jul 17 '19 at 10:45
  • Its working after adding below lines.. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] but the case is its not automatically redirectly to without extension URL. I have to manullay remove the .php from the url and then hit the enter its loading the page but my requirement is automatically redirecting to the without extension url – sumit kundan Jul 17 '19 at 11:17

1 Answers1

0

You can use:

# To externally redirect without .php
RewriteCond %{THE_REQUEST} \s/+(.+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# To internally rewrite to .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Croises
  • 18,570
  • 4
  • 30
  • 47
  • When i am using then in that case POST data is not working. If am trying to send form data one page to another then in that case request is not sent. For instance, I have a login.php page where i have form there data send to login_register.php page using POST method but after using the rewrite condition which are writing in that case form data is not reached on that page – sumit kundan Jul 18 '19 at 04:53
  • 1
    Send your data to "login_register" without ".php" – Croises Jul 18 '19 at 10:48