Welcome to WebmasterWorld Guest from 3.227.3.146

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

.htaccess and Wordpress & Install in Sub-Directory

Serving Wordpress From Site Root While Installd in Sub-Directory

     
12:57 pm on Mar 3, 2018 (gmt 0)

Preferred Member

10+ Year Member

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


Hello,

I'm in the process of painfully converting a huge, static content site over to Wordpress. I installed WordPress in a sub-directory called "wordpress." Right now, everything is going fine.

Soon, though, I want Wordpress to go live. I've read tons of articles about this, and the process seems fairly simple. Change the index.php file to point to the wordpress install, change the site url in Settings and move the .htaccess and index.php file to the root.

However, I have one rather unique problem that I've been unable to find an answer too.

My huge, static content site still exists on the server...and will for the remainder of the year.

I'm having to "convert" the site from static to Wordpress "page by page." In essence, once Wordpress goes live, I'll have a partial CMS site of about 100 pages (using Wordpress) and a static site of 1000's of pages that will slowly, over the next 8 months or so, disappear as I convert the static pages to CMS pages. I hope this makes sense.

My plan is to re-write much of the old, static content, upload photos, then publish it on Wordpress. As I do this, I'll remove the pages from the static site and put in redirects to the new pages. A slow affair, but one that shouldn't cause too many problems, I hope.

However, since my static site is still live and I just can't "nuke it", I need the existing .htaccess file I use for my static website (which contains piles of redirects) for the next 8-10 months or so. And this is where I need some advice.

How do I combine the existing Wordpress .htaccess with my existing .htaccess file that contains piles of redirects?

Here's the beginning of my "combined" .htaccess file that I worked out and which will be installed in "root", and I'm wondering if I'm going 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


Everything beneath #End Compression (which runs 100's of lines) is just redirects from old .htm pages (made in 2002-2004) to newer .php pages (albeit still static) made in 2010 and later.

Anyways, I was hoping to get some members thoughts about this. As well as any other issues that you might think arise during this process.

Also, since I plan to use WP Cache, I was going to delete all references in the .htaccess file to cache control. Is that a good idea?

Also, two more questions too. What do I do with the .htaccess file in the current wordpress folder? Do I keep it there? Or delete it?

And last but not least, what do I do with the index.php file in the Wordpress folder? Do I also keep it as is? Delete it? Or have a "blank" index.php file?

Thanks for any help/advice

Jim
1:39 pm on Mar 3, 2018 (gmt 0)

Preferred Member from CA 

Top Contributors Of The Month

joined:Feb 7, 2017
posts: 579
votes: 60


I run a couple of WP installs, all in subdirectories, together under one hosting service. I don't move anything to root. Just leave it "as is" and it will be fine. If you move anything to root you will interfere with your original site.

I would also not name the subdirectory "wordpress", as the bots can easily guess this. Please name it something else. They have an easy enough time annoying us without encouragement!

You should be able to get an automated script to be able to migrate your content, in a rough way. Then you can tweak each document. That might be easier. There are migration plugins.

There are many other CMSs. Wordpress is popular, I do like it, but it is hack-prone, so be very careful of security. Bots target WP installs specifically, because they are easier to break into. While WP core is solid, all those pesky plugins can be a security hole.

Why did you choose WP?
1:59 pm on Mar 3, 2018 (gmt 0)

Preferred Member

10+ Year Member

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


Hi,

I won't be moving Wordpress to "root." It will remain installed where it is. However, I want it to "run" off root. Thus, the home page in Wordpress will appear in the address bar as www.mydomain.com and not www.mydomain.com/wordpress/

Hence the need to move the index.php and .htaccess to root and to reconfigure the index.php file.

Which then leads to all sorts of questions about the .htaccess file I have.

I chose Wordpress mainly because I was able to figure it out. i bought a premium theme that's been around a while (Avada) and was able to easily customize it - with no plugins and just 50 lines of custom CSS and no hacking - to look almost identical to my static site. So the transition will be rather invisible other than the new url's.

I'm keeping plugin useage to an absolute minimum. WP Super Cache, Yoast SEO and, for now, Revision Control, are about it.

Migration plugins won't really work well for my organization disaster of a static site that I have. The content needs rewriting and cleaning up, and pages that span "multiple pages" on the static site will only go to one page on the WP site. Moreover, all the photos on the static site aren't "retina ready." The new photos on the WP site, obviously, will remain that way.

I wouldn't mind changing the name of the sub-directory that's now called Worpress. But won't doing that now mess everything up? I already have built 100 or so new pages with Wordpress, and have uploaded 100's of images.
2:25 pm on Mar 3, 2018 (gmt 0)

Preferred Member from CA 

Top Contributors Of The Month

joined:Feb 7, 2017
posts: 579
votes: 60


Better to change the subdir name now rather than when you have 1,000s of pages. "Wordpress", other than in root, is the next most common install dir name.
3:36 pm on Mar 3, 2018 (gmt 0)

Administrator from US 

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

joined:Dec 27, 2006
posts:4559
votes: 363


The order of your htaccess file is important and the order posted above is not correct. That part at the top that begins with
# BEGIN WordPress
goes at the very end after everything else. The canonical rewrites should be just above that WP snippet. To get definitive assistance on that .htaccess file, I would take that part of this question to the Apache forum [webmasterworld.com] explaining the environment there as you have here. The Apache gurus don't frequent the WP forum that often.

WP can be made secure with a few settings and edits. CHMOD is your friend to ensure that particular files are safer. There's no requirement that your .sql tables have a "wp-" prefix as long as your chosen prefix agrees with configurations. It really doesn't matter what you name the install folder because whatever /folder/ it is in is exposed in every URL path it uses. It is true that a /wordpress/ folder name will mean it is preconfigured for a lot of automated hits. I suggest using a captcha on the admin login to slow down the automated hits.

I have only one install running from a folder below root and it has run without issues close to 11 years. Most installs I manage are installed in the root directory, but the instructions to install in a sub-directory are fairly clear and simple. The htaccess file and index.php go to the root directory and WP handles the rest.
10:00 pm on Mar 3, 2018 (gmt 0)

Preferred Member

10+ Year Member

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



Thanks for the info. I posted this question in the Apache forum.

The htaccess file and index.php go to the root directory and WP handles the rest.


This brings up another question. What do I do with the original Wordpress .htaccess file currently in the "wordpress" folder? Do I leave it there, or delete it? Same thing for index.php - do I leave it there or delete it?

Finally, do I need to change anything with the original .htaccess file Wordpress installed.


# 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


I noticed that the ReWrite Base is "/wordpress/" and the RewriteRule is ./wordpress/index.php

Do I need to change any of that to make Wordpress run "off root" if the .htaccess file is moved out of the wordpress sub-directory and into root?
3:04 am on Mar 4, 2018 (gmt 0)

Administrator from US 

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

joined:Dec 27, 2006
posts:4559
votes: 363


Once the htaccess file shared above is sorted out, it belongs in the root directory, as does the index.php file IF you want it to run as example.com/ rather than example.com/wordpress/ - that is up to you. Better explanations of your options and the costs/benefits of either format are at the WordPress Codex [codex.wordpress.org] site, good reading if you aren't sure how you want it to work when it is finished. If using the example.com/wordpress/ format, then index.php belongs in the /wordpress/ directory. Whichever you decide, do not edit that WP snippet or block, it needs to be as it was generated to agree with your configurations (Settings).

Personally I would not delete cache rules that are working, and then add a plugin to do the same thing. The plugin just puts the rules back in your htaccess file and adds another layer of things to update. It is handy for people who don't really understand caching or how to do it, but it looks like you are handling that as it is. Some plugins add every option under the sun in the filename extensions which you would probably want to edit back to what you are using.