Welcome to WebmasterWorld Guest from 54.166.181.58

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

.htaccess file for a combination static/wordpress site

Is this .htaccess file workable?

     
9:52 pm on Mar 3, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts: 512
votes: 5


Hello,

I originally posted this in the Wordpress forum, but the moderator suggested to post this here. In a nutshell, I have a large static site that I'm converting to Wordpress. Wordpress is installd in a sub-directory and will remain installed there.

However, I want the new "Wordpress" version of the site to appear to run off root (aka, so it shows www.mydomain.com instead of www.mydomain.com/wordpress/ in the address bar)

To further complicate matters, the static site is still live - I just can't "nuke it" - since I have to convert it to WP page by page over the next 8 months or so. Thus, the static site (and it's .htaccess file) need to co-exist with Wordpress (and it's .htaccess file) for the remainder of the year until the static site has disappeared.

So my question is this...how to combine the .htaccess files for my static site and the .htaccess file for Wordpress into one single .htaccess file.

This is what I've come up with so far, but would like to know if I'm likely to run into problems because of it:


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

RewriteOptions inherit
Options +Includes
RewriteEngine on

# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

AddType image/svg+xml svg svgz
AddEncoding gzip svgz

# Begin Cache Control
Header unset Pragma
FileETag None
Header unset ETag

# cache images/pdf/css docs for 1 Month
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|svg|css)$">
Header set Cache-Control "max-age=2629000, public, must-revalidate"
Header unset Last-Modified
</FilesMatch>

# cache html/htm/xml/txt diles for 2 Days
<FilesMatch "\.(xml|txt|xsl|js|woff)$">
Header set Cache-Control "max-age=172800, must-revalidate"
</FilesMatch>

#End Cache Control

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/htm
AddOutputFilterByType DEFLATE text/shtm
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
#End Compression

#Beneath Here Are 100's of Re-Directs

So will this .htaccess file work? Or is it fatally flawed? I was thinking of removing all "cache control" and "compression" elements from the .htaccess file, so as to not run into problems with the WP cache plugin I'll be using.

The other question I have relates to what to do with the original .htaccess file for Wordpress that's currently installed in the "wordpress" sub-directory. Do I leave it there? Or remove it entirely?

The final question I have relates to converting to HTTPS. Before July I'll be needing to convert the site to HTTPS. I've successfully converted several small static sites to HTTPS without problems. But those sites aren't a combo of "static + wordpress." I've used the following code to convert these small static sites to HTTPS. Will this code also work for the website I'm converting to Wordpress and will be a combo "static + wordpress" site for the remainder of the year?


RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
10:38 pm on Mar 3, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11444
votes: 171


just speaking of the general order of things:
- the 100s of specific redirects (that you aren't showing) should be first among the mod_rewrite directives, ordered from most specific to most general.
- the hostname and protocol canonicalization redirects should be next, combined into a single ruleset. you can find many typical examples of this code in this forum.
- the internal rewrite ruleset for wordpress should be after all the external redirects.

#Beneath Here Are 100's of Re-Directs

are you using the RewriteRule or the Redirect(Match) directive for these?
10:50 pm on Mar 3, 2018 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 24, 2002
posts: 512
votes: 5


For re-directs, I'm using the simple - and probably outdated - form:


Redirect permanent /folder-name/page-name.htm http://www.mydomain.com/folder-name/new-page-name.php
1:34 am on Mar 4, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11444
votes: 171


You should change these all to RewriterRule directives.

This is because, when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file.

source: [httpd.apache.org...]
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members