Can .htaccess fix this problem?

BT69

BANNED
Joined
Sep 23, 2024
Messages
65
Reaction score
59
1. ) 2 years ago a I set up an html site without a wordpress blog

2.) 18 months later I installed a wordpress blog in a different directory on same domain

3. ) I linked to the blog from the main page (index.php)

I've deleted the html site but I want to keep the wordpress blog.

Can I use .htaccess to redirect to wordpress blog's subdirectory? Or, will I have to do a new install of wordpress in the domain's root directory?
 
Can I use .htaccess to redirect to wordpress blog's subdirectory?
Yes, you can
Something like this
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteRule ^(.*)$ /subdirectory/$1 [L]
</IfModule>
Replace /subdirectory/ with the actual name of your subdirectory.
 
Yes, you can
Something like this
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteRule ^(.*)$ /subdirectory/$1 [L]
</IfModule>
Replace /subdirectory/ with the actual name of your subdirectory.


I'm really weak in my knowledge of .htacess so kindly tolerate my attempt to understand this.

Where it says "RewriteCond %{REQUEST_FILENAME} !-f " "RewriteCond %{REQUEST_FILENAME} !-d" Do I write in "index.php" for the old site?
 
I'm really weak in my knowledge of .htacess so kindly tolerate my attempt to understand this.

Where it says "RewriteCond %{REQUEST_FILENAME} !-f " "RewriteCond %{REQUEST_FILENAME} !-d" Do I write in "index.php" for the old site?
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?yoursite.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?yoursite.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>
This should ensure all your request to your root domain are redirected
Change according for my_subdir and yoursite
my coding is quite rusty :suspicious: if anyone has a better way go nuts
 
Why would you throw away the homepage, just install one more wordpress and recreate your html or move the blog from the folder to the root than make category called blog in your wp so your old urls are still same...
 
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?yoursite.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?yoursite.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>
This should ensure all your request to your root domain are redirected
Change according for my_subdir and yoursite
my coding is quite rusty :suspicious: if anyone has a better way go nuts
Honestly, just go to your hosting's live service/ticket and ask them to fix it for you.
9 outta 10 times they would do it for free
 
You have: site dot com (index file deleted) and site dot com / blog

Everything you need to do is 301 redirect from site com to site com / blog

You can upload a simple html index file with 1 line of code that will do 301 redirect.

You can ask your hosting to do it for you, or from your C-panel you can do it yourself, just find Redirections option

If you want via .htaccess (most simple one) just enter this anywhere in .htaccess and save.

RewriteEngine on
Redirect 301 /index.html /site.com/blog.html


You can do it via PHP file, any will work, just upload a file to root of website or edit .htaccess or use cpanel or ask hosting company to assist you. They must do it for free.


Since you wrote PHP index file actually, here you go, just upload another index .php with this

PHP:
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.site.com/blogname.html");
exit();
?>
 
Back
Top