Redirect without www

E1A

Member
Registered
Joined
May 12, 2022
Messages
16
Points
3

Reputation:

/in httpdocs, I pasted the following code into htaccess at the very bottom. But, unfortunately, it didn't work for me. I wonder where I'm doing wrong? There is already no problem with https redirection, but when I type with www, it still detects and gives an error like two separate sites. how do I redirect it to being without www? Thanks.

Code:
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,QSA]
</IfModule>
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,533
Points
523

Reputation:

Apache config:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
 

E1A

Member
Registered
Joined
May 12, 2022
Messages
16
Points
3

Reputation:

Apache config:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
BattleKingI have added the code to the htaccess file. However, it still gives an error that the page was not found when I typed www :(

Ekran Resmi 2022-07-22 11.47.06.jpg
 

one_finger_man

Well-known member
Registered
Joined
Jan 20, 2022
Messages
421
Points
53

Reputation:

did you disable the redirect on your server and than try this one

HTML:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>



<IfModule mod_rewrite.c>
    RewriteEngine On

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    RewriteBase /

    #    This line may be needed to workaround HTTP Basic auth issues when using PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
    #   Uncomment those 3 lines bellow to automatically redirect from "http" to "https" and remove "www" if needed
    #   remember to replace domain.com with your own domain name.   
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www.your url.com [NC]
    RewriteRule (.*) https://your url.com/$1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>
 
Top