skip to Main Content

I’m trying to setup a classic .htaccess file for url rewriting.

For the moment I’m trying to simply rewrite login.php to login

I have tried using the following .htacess file :

RewriteEngine on
RewriteBase /

# Not Directory
RewriteCond %{REQUEST_FILENAME} !-d

# Not file
RewriteCond %{REQUEST_FILENAME} !-f

# Not Link ?? No Need.
#RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^login/$        login.php               [L]

Which gives me the following when I try to access http://MYIP/login

http://MYIP/https://MYIP/login/

And I also tried using the following :

### BEGIN - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
<IfModule mod_rewrite.c>
RewriteEngine on

# RewriteBase is set to "/" so rules do not need updating if the
# installation directory is relocated.  It is imperative that
# there is also a RewriteCond rule later that can effectively get
# the actual value by comparison against the request URI.
#
# If there are _any_ other RewriteBase directives in this file,
# the last entry will take precedence!
RewriteBase /


# Redirect directories to an address with slash
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$  $1/ [R]

# Send all remaining (routable paths) through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Determine and use the actual base
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)1$
RewriteRule ^.*$ %2index.php [QSA,L]

</IfModule>
### END - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###



RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$        /$1$2/ [L,R=301]

RewriteRule     ^/login/$           ^/login.php$    [L]

And I got the same result.

Under the administration panel in WHMCS I set the url rewrite to Basic URLs.

Opening in private navigation I have error 404.

2

Answers


  1. Chosen as BEST ANSWER

    After some search and help from @RavinderSingh13, I get to the following working .htaccess :

    ### BEGIN - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
    <IfModule mod_rewrite.c>
    RewriteEngine on
    # RewriteBase is set to "/" so rules do not need updating if the
    # installation directory is relocated.  It is imperative that
    # there is also a RewriteCond rule later that can effectively get
    # the actual value by comparison against the request URI.
    #
    # If there are _any_ other RewriteBase directives in this file,
    # the last entry will take precedence!
    RewriteBase /
    
    # Redirect directories to an address with slash
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+[^/])$  $1/ [R]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    #Change
    RewriteRule ^login$ ./login.php [L,NC]
    
    
    # Send all remaining (routable paths) through index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Determine and use the actual base
    RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)1$
    RewriteRule ^.*$ %2index.php [QSA,L]
    
    </IfModule>
    ### END - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
    

  2. With your shown samples could you please try following. Please make sure you clear your browser cache before testing your URLs. Looks like you already had 1 Rule for non existing directories and non existing files so place your Login rule before it. I have put htaccess rule file here only from <IfModule mod_rewrite.c> to </IfModule> here.

    ### BEGIN - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
    <IfModule mod_rewrite.c>
    RewriteEngine on
    # RewriteBase is set to "/" so rules do not need updating if the
    # installation directory is relocated.  It is imperative that
    # there is also a RewriteCond rule later that can effectively get
    # the actual value by comparison against the request URI.
    #
    # If there are _any_ other RewriteBase directives in this file,
    # the last entry will take precedence!
    RewriteBase /
    
    # Redirect directories to an address with slash
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+[^/])$  $1/ [R]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^login/?$  login.php$ [NC,L]
    
    # Send all remaining (routable paths) through index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Determine and use the actual base
    RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)1$
    RewriteRule ^.*$ %2index.php [QSA,L]
    
    </IfModule>
    ### END - WHMCS managed rules - DO NOT EDIT BETWEEN WHMCS MARKERS ###
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search