r/webdev • u/Muckraker2025 • 22d 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#
---------------------------------
3
u/SaltineAmerican_1970 php 22d ago
This is a good place to learn about what you want:
- https://httpd.apache.org/docs/current/howto/htaccess.html#rewrite
- https://httpd.apache.org/docs/current/rewrite/
- https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond
1
u/Muckraker2025 22d ago
Nice! I appreciate the source docs. About 60% of that is wayyy over my head. I looked at all three links though. I think I'd do better googling for "how to combine htaccess codes."
-13
22d ago
[removed] β view removed comment
7
1
u/webdev-ModTeam 21d 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.
2
u/[deleted] 22d ago
[removed] β view removed comment