homepage Welcome to WebmasterWorld Guest from 23.22.194.120
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
non-www rewrite on Wordpress directory
keeps changing on its own?
lee_sufc




msg:4624322
 8:20 pm on Nov 18, 2013 (gmt 0)

A while back, I posted a question about a non-www re-write issue on a /blog (Wordpress) directory on my site.

The full details of this are at [webmasterworld.com...] however, as a brief overview; if visiting the non-www version of the /blog directory, rather than redirecting to www.mysite/blog, it would redirect back to home?

Anyway, I resolved this by putting the non-www re-write htaccess instructions into my root directory and deleting them from the Wordpress directory.

This seemed to work; however, somehow, it keeps changing back? I have to keep manually editing the htaccess file on the blog and deleting the Wordpress instructions?

Does anyone know why this is is happening?

below is a copy of what my htaccess looks like (in the root directory):

RewriteOptions inherit
RewriteEngine On

RewriteCond %{HTTP_HOST} ^mysite\.net [NC]

RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]

#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
#End Gzip

#cache html and htm files for one day
<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>

#cache css, javascript and text files for one week
<FilesMatch ".(js|css|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>

#cache flash and images for one month
<FilesMatch ".(flv|swf|ico|gif|jpg|jpeg|png)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

#disable cache for script files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>

#Redirect old affs
RewriteEngine on
RewriteBase /
RewriteRule ^aff/(.*) /CV_Writing_Services.htm [R=301,L]
RewriteEngine on
RewriteBase /
RewriteRule ^idevaffiliate/(.*) /CV_Writing_Services.htm [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.net$
RewriteRule ^Professional\ CV\.htm$ "http\:\/\/www\.mysite\.net\/ProfessionalCV\.htm" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.net$
RewriteRule ^How\ to\ write\ a\ CV\.htm$ "http\:\/\/www\.mysite\.net\/how\-to\-write\-a\-CV\.htm" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.net$
RewriteRule ^JobSeekerTools\.htm$ "http\:\/\/www\.mysite\.net\/blog\/" [R=301,L]

Redirect 301 /Graduate-CV-Advice.htm http://www.mysite.net/blog/graduate-cv-example-help/
Redirect 301 /NotNeededCV.htm http://www.mysite.net/GoodCV.htm
Redirect 301 /Howmanypages.htm http://www.mysite.net/GoodCV.htm
Redirect 301 /how-to-write-a-CV.htm http://www.mysite.net/GoodCV.htm
Redirect 301 /CVprofiles.htm http://www.mysite.net/GoodCV.htm

Redirect 301 /blog/have-you-ever-lied-on-your-cv/ http://www.mysite.net/blog/should-i-lie-on-a-cv/
Redirect 301 /blog/cv-embellisher-banned-for-a-year/ http://www.mysite.net/blog/should-i-lie-on-a-cv/

RewriteCond %{HTTP_HOST} ^mysite\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.net$
RewriteRule ^Free\-CV\-Review\.htm$ "http\:\/\/www\.mysite\.net\/Free\-CV\-Review\.php" [R=301,L]

RewriteRule ^blog/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule blog/ /blog/index.php [L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^Employment_gaps\.htm$ "http\:\/\/www\.mysite\.net\/blog\/medicine\-for\-a\-spotty\-cv\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.net$
RewriteRule ^greatinterviewtips\.htm$ "http\:\/\/www\.mysite\.net\/blog\/10\-job\-interview\-no\-nos\/" [R=301,L]

 

lucy24




msg:4624337
 10:12 pm on Nov 18, 2013 (gmt 0)

Before we begin:

#1 You do not need quotation marks in a rewrite/redirect target, and you do not need to escape directory slashes, colons, hyphens outside of grouping brackets, or anything in a target (ever).

#2 Never combine mod_rewrite (RewriteRule) with mod_alias (Redirect by that name) in an htaccess file. External redirects (301/302) have to execute before any internal rewrites, but mod_rewrite-- all of it-- will execute before mod_alias. You can't change this. (It may or may not be possible to force a different order if it's happening in the config file of your own server.)

if visiting the non-www version of the /blog directory, rather than redirecting to www.mysite/blog, it would redirect back to home?

Do you mean that it does, or that you want it to? Nothing should ever redirect to home. Except, ahem, requests for non-www home.

Anyway, I resolved this by putting the non-www re-write htaccess instructions into my root directory and deleting them from the Wordpress directory.

This seemed to work; however, somehow, it keeps changing back? I have to keep manually editing the htaccess file on the blog and deleting the Wordpress instructions?

Using mod_rewrite in more than one htaccess file along the same path is just asking for trouble. It uses different inheritance rules than all other apache mods; the only safe approach is to have only one of it.*

CMS such as WordPress rely on rewriting, so every time you do something with the software, it will install a new htaccess. So it's doubly essential to keep a copy of your own version, and keep it up to date.

The optimal form for a domain-name-canonicalization redirect is a single condition:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
using the exact form of your domain name that you want to use. Everything else gets redirected. The (blahblah)? aspect is for http 1.0.



* Do as I say. Not as I do. I have a slew of image-specific RewriteRules inside a <FilesMatch> envelope. Nobody told me you're not supposed to.

lee_sufc




msg:4624338
 10:19 pm on Nov 18, 2013 (gmt 0)

Hi Lucy,

I don't *want* anything within the htaccess file within the /blog directory. However, you mention that Wordpress automatically updates it now makes sense...I'm guessing I have to now keep an eye on it each time I do anything.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved