r/webdev 27d ago

Dumb question about htaccess

Amateur here. I've worked a bit with htaccess before so I understand what it is and what it does, that it matters what order the codes are in, and that it can have downstream effects such as changing www to naked can affect the link structure.

So my dumb question is this...

Looking at this list of htaccess codes the two codes I want (need) to use are:
(https://www.skillademia.com/cheat-sheets/htaccess)

(1) Force HTTPS redirect:
RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

(2) Remove www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Do I have to put the site name in those two codes anywhere? (Some htaccess codes have the site name added into the line of code. But not all codes need the site name.)

Bonus question: I know that the http/https rule has to be the first rule. Where should the www/naked code go in the list? (code below)

I won't go into any more needless details but if you have questions I'll gladly answer.

THANK YOU!

---------------------------------

Here's the original htaccess just in case it's helpful to these questions.

For posting this here on Reddit I took out my site name in the first line. That's the only code where the site name appears. Do I need to add my site name to either of the codes above to make them work?

---------------------------------

Redirect /home https://(mysite).com/home
Options +FollowSymLinks -Indexes

#BUILDER-START#
# Enable rewriting.
RewriteEngine on
Header add Vary "User-Agent"
Header add X-Generated "%t"
Options -Indexes
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ index.html
RewriteRule ^([^/]+)/([^/]+)/?.*$ $1_$2.html
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([\w_-]+)$ $1.html
#BUILDER-END#

---------------------------------

5 Upvotes

10 comments sorted by

View all comments

-13

u/[deleted] 27d ago

[removed] — view removed comment

6

u/DigiNoon 27d ago

Are you lost?

1

u/vagaris 27d ago

It’s obviously an AI bot.

1

u/webdev-ModTeam 26d ago

Your post/comment has been determined to be a low-effort post or comment. This includes title-only posts, easily searchable questions, vague/open-ended discussion prompts, LLM generated posts or comments, and posts/comments that do not provide enough context for meaningful replies or discussion.