Как добавить некоторую перезапись URL в WHMCS?

#apache #.htaccess #mod-rewrite #url-rewriting #whmcs

#apache #.htaccess #мод-перезапись #url-перезапись #whmcs

Вопрос:

Я пытаюсь настроить классический файл .htaccess для перезаписи URL.

На данный момент я пытаюсь просто переписать login.php в login

Я попытался использовать следующий файл .htacess :

 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]
 

Что дает мне следующее, когда я пытаюсь получить доступ http://MYIP/login

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

И я также попытался использовать следующее :

 ### 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]
 

И я получил тот же результат.

В панели администрирования WHMCS я установил перезапись URL-адреса на основные URL-адреса.

При открытии в частной навигации у меня ошибка 404.

Комментарии:

1. Вы получаете какую-либо ошибку при нажатии на URL http://localhost:80/login ?

2. @RavinderSingh13 Нет ошибок, когда я открываю его в приватной навигации, теперь у меня ошибка 404

Ответ №1:

С вашими показанными примерами не могли бы вы попробовать следующее. Пожалуйста, убедитесь, что вы очистили кэш браузера перед тестированием URL-адресов. Похоже, у вас уже было 1 правило для несуществующих каталогов и несуществующих файлов, поэтому поместите перед ним свое правило входа. Я поместил файл правила htaccess здесь только <IfModule mod_rewrite.c> отсюда </IfModule> .

 ### 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 ###
 

Ответ №2:

После некоторого поиска и помощи от @RavinderSingh13 я перехожу к следующему рабочему .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 ###