.htaccess and re-direct

I have a website with re-direct. I also have Wordpress installed in directory /blog.

The redirect is preventing Wordpress from working correctly.

The redirect is in .htaccess and is like: Redirect 301 / [noparse]http://www.domain.com/[/noparse]

How can I correct this issue so the entire domain.com will redirect to [noparse]http://www.domain.com/[/noparse]

I have the url set to [noparse]http://www.domain.com/[/noparse] in general settings in Wordpress.

Thanks for the help!

I don’t know if I’ve understood your question properly. Are you trying to redirect from domain.com to www.domain.com, so that the www is always used? If so, this should work:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.example\\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

Yeah, that does not work at all.

Sounds like you need to move all your wordpress files into the root folder, then change the absolute path in the wp-config file

za,

A Redirect like that would cause a loop IF located in the domain.com’s DocumentRoot. TB’s code is accurate, correct and the most efficient use of mod_rewrite. Your “it doesn’t work” is a useless comment, though, as you did not give any indication of what’s not working (if mod_rewrite is not enabled, you should get 500 errors; if it is, .htaccess should be the file examined by Apache - you are using Apache, aren’t you? - and the code is picture perfect).

As usual (with mod_rewrite questions), please specify EXACTLY what you’re trying to do and provide us with the code you’re using as the code often has some error which can be quickly spotted by the trained eye.

Regards,

DK

Sometimes your server can be picky on what it will do inside the .htaccess file. I would hit up your web hosting company about making changes, because this should work.

To say the code is not working is perfectly valid since it is not. I never said the code itself is written wrong as it is not because it is the first type of code I had tried first as it is in my coding toolbox. Though it creates issues. The server should be apache as that is what the host has told me.

Bottom line I need all domains to be [noparse]http://www.domain.com/[/noparse]

I need the wordpress directory and root directory to work. Wordpress directory = /blog

Not sure how I could better explain this.

Thanks!

za,

We’re just not connecting. Use the following code in the DocumentRoot’s .htaccess:

RewriteEngine on
# force www but substitute your domain name
RewriteCond %{HTTP_HOST} !^www\\.example\\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

# place WP's code here but [COLOR="#FF0000"]WITHOUT [/COLOR]the <IfModule> wrapper, without the RewriteCond %{REQUEST_URI} index.php but with the RewriteBase /blog
RewriteBase /blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? index.php [L]

Regards,

DK

That did it dklynn, thank you!

Is there a way so it re-directs to http:// instead of just www. though?

z,

Sure. Reverse the logic of the first block like

# force NON-www but substitute your domain name
RewriteCond %{HTTP_HOST} !^example\\.com$ [NC]
RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

Note: This will send everything (parked domains, in particular) to http://example.com.

That, too, is in the tutorial (and sample code) linked in my signature so it was there for the taking if you’d only look around just a bit.

Regards,

DK