Apache rewrite question

Hello,

Does anyone have a snippet of an apache config file that demonstrates a simple rewrite rule for prepending the "www" portion to the domain name? I know the basics of apache configuration but the rewrite stuff (especially the regular expresions!) is very confusing to me.

I'm just trying to get mydomain.com to always load up in a browser as www.mydomain.com.

Thanks much,

Jeff

2 Replies

Hi,

you don't need rewrite for that. Rewrite is not recommended for security reasons. Do this in your apache config:

yourdomain.com - redirect to www.yourdomain.com

ServerName yourdomain.com

ServerAdmin admin@yourdomain.com

Redirect / http://www.yourdomain.com/

This is perfect!

Thanks much!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct