Site icon Hip-Hop Website Design and Development

Need help rebuilding lost htaccess file

I originally posted this on Stack Overflow (7 months ago). I didn’t receive any answers and was not in a position to pursue it further. As of now I am working on resolving this, and would greatly appreciate assistance from someone familiar with WP and htaccess.

Some time ago I installed Magento in the sub directory of a site with many apps on it, and the Magento downloader/installer replaced the .htaccess file in my root.

The automated backups which run via a wordpress installation happened to NOT be capturing the few files in the root folder. I have no back-up.

This wouldn’t be so bad if I actually knew and understand all that was in that .htaccess file. it has been slowly created over a period of years!

What I am looking for is some assistance with rebuilding it. Already I am coming across issues.

For instance, when I try to access a fold other than my wordpress folder, I am rerouted to the 404 of wordpress.

For instance, I have a proxy app in the subfolder /proxy, but if I go to mysite.com/proxy I see in the address bar: mysite.com/proxy , and the wordpress 404.

I’ve greatly enjoyed learning increasing amounts of regex in past months, and getting my head around .htaccess redirects, rules, etc. So I’d like to more than solve these issues, and actually understand how they are solved.

Here is my root .htaccess as it stands (pulled together from a few miscellaneous notes I had on record:

<Files .htaccess>
order allow,deny
deny from all
</Files>

# Redirect
#<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteCond %{REQUEST_URI} !^/site/
#RewriteCond %{HTTP_HOST} ^www.
#RewriteRule (.*) http://mydomaint.com/site/$1 [R=301,L]
#</IfModule>

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

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ site/index.php [L]

</IfModule>

I get the impression there is repetition and redundancy in that code. And that it is missing lines to pick up on subfolders that are NOT the wordpress one (which is in /site by the way).

I have included showing you what was commented out, as it may help with seeing where I went wrong, or identifying how it should be set up.

What I need is that all requests for:

Are directed to mydomain.com/site

Requests for any other subfolder (assuming it exists) should go through to to the folder requested (e.g. mydomain.com/proxy or mydomain.com/shop are passed through to their respective folders /proxy and /shop).

Requests for subfolders which do not exist, should be routed through to mydomain.com/site

I am not sure just yet if anything else has been broken, but I can bring that to the table if and when I discover it.

I should add that I have also tried this:

order allow,deny
deny from all

# Redirect
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/site/
RewriteCond %{HTTP_HOST} ^www.
RewriteRule (.*) http://jonathanevatt.com/site/$1 [R=301,L]
</IfModule>

But something odd occurs with this. If I browse to www.mydomain.com (or mydomain.com) I end up with with that in the address bar, and this appearing on a blank page (as a line of text at the top left of the page:

/home/jonathan/public_html/app/Mage.php was not found

This is exactly what was happening after the installer whipped out my .htaccess file. I have not idea where or how that is being called up, as I see nothing in the .htaccess leading to this address being called. It is very perplexing.

ALSO
I did manage to find a back-up of some rules I had in my htaccess file, which were there to redirect requests for various types of content from my old Joomla site. These rules are:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^en/Page-[0-9]+.html /site/blog/ [R=301,L]
RewriteRule article&id=([0-9]+) /?p=$1 [R=301,L]    #CATCH ?option=com_content&view=article&id=307&catid=89&Itemid=55
RewriteRule ^articles-other-writing/(Page-[0-9]|index).html /site/blog/ [R=301,L]
RewriteRule ^articles-other-writing/[a-zA-Z-]+/(Page-[0-9]|index).html /site/blog/ [R=301,L]
RewriteRule ^what-is-love/([a-zA-Z0-9-/._=?&]+) /site/blog/ [R=301,L]
RewriteRule ^media/audio/([0-9a-zA-Z_]+.mp3)$ /wp-content/uploads/audio/$1 [L,R=301]
RewriteRule ^[A-Za-z-]+/[a-z-]+/[a-z-]+/([0-9]+)-.+ /?page_id=$1 [R=301,L]
RewriteRule ^/swine-flu.html$ /site/tags/swine-flu/ [R=301,L]
RewriteRule ^events/event-descriptions/([A-Za-z-]+).html$ /site/events/$1/ [R=301,L]
RewriteRule ^[0-9]{8}([0-9]*)/(articles|great-products|others-videos|jonathan-s-blog)[a-zA-Z0-9-/.]+ /?p=$1 [R=301,L]   # CATCH POSTS 1
RewriteRule ^[0-9]{8}([0-9]*)/services[a-zA-Z0-9-/.]+ /?page_id=$1 [R=301,L]                # CATCH PAGES 1
RewriteRule ^myblog[a-zA-Z0-9-/.] /site/blog/ [R=301,L]    #CATCH MYBLOG
RewriteRule ^view-by-tag/([a-zA-Z-]+)/([a-zA-Z0-9-/._=?&]+) /site/tags/$1/ [R=301,L]

I should probably integrate them into the new htaccess file just in case there are still links out there pointing to important content on the old Joomla system.