Redirect all pages to non www except one page

ArjunSuhass

Registered
Feb 9, 2022
3
0
1
Mumbai
cPanel Access Level
Website Owner
I want to redirect all my internal pages(eg: example.com/about) to their non www version but I want my web hosting to redirect to it's www version(Example Domain)

I searched many articles on the internet but it could not work.

If set both rules then the internal pages get redirected fine but the homepage gets trapped in a loop.

I don't know how to code so please it's a request if you could write the code which I should paste in my .htaccess file

Currently I have set all pages to redirect to their non www versions(even homepage) with the below code:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</IfModule>
# BEGIN Sitepad
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END Sitepad
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
10,360
1,632
363
cPanel Access Level
Root Administrator
Hey there! This wouldn't be directly related to the cPanel tools, but what about something like this? In this example, if the URI has /staging the redirect does not apply.

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/staging/
RewriteRule ^(.+) - [PT]
RewriteRule (.*) /livesite/$1 [L]
You may need to mess around with that a bit to get the desired results, but something along those lines should get you started in the right direction.
 
  • Like
Reactions: Spirogg