Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - Subdirectory - htaccess

I have Wordpress installed in a subdirectory:

/public_html/blog/

I want to be able to access the blog like this:

http://example.com/blog

and posts like this:

http://example.com/blog/category/postname

In general settings I have the "WordPress Address (URL)" set to:

http://example.com/blog

Permalinks is set like:

/blog/%category%/%postname%

In the subdirectory (/public_html/blog/) I have an .htaccess like:

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

Everything works EXCEPT for being able to access the blog Home page at: http://www.example.com/blog Doing that sends me to the "Wordpress 404 page not found" page.

I'd be very grateful for a solution!

EDIT

I'm an idiot - I missed something vital. I needed to also change the Site URL in Wordpress > General to:

http://example.com/blog

Doing that and then removing /blog/ from the permalink structure made everything work. I probably wouldn't have spotted this if @IanB hadn't picked up the /blog/ bit not being necessary. Thanks...

like image 591
Leon Avatar asked Mar 03 '12 16:03

Leon


People also ask

Does htaccess work on subdirectories?

htaccess file are applied to the directory in which the . htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been . htaccess files in directories higher up.

How do I use subdirectory in WordPress?

Click on the File Manager option. Your WordPress files should be located in the public_html directory. You will want to create a new subdirectory in this section. Add a new directory by creating a new folder.

How do I create a subdirectory in WordPress?

Usually it is the /public_html/ folder. If you already have WordPress installed in the root folder, you will see your WordPress files and folders. Next, you need to right-click and select 'Create new directory' from the menu. You need to be careful when choosing the name for your subdirectory.

How do I move from root to subdirectory in WordPress?

Click "General" on the dashboard on the left side of the screen. Change the address to the new directory in the "WordPress address (URL)" box. For example, if you want to have WordPress run in the subdirectory "blog," type "http://yourdomain.com/blog." Keep the Site Address (URL) field the same. Click "Save Changes."


1 Answers

2 things come to mind. I don't think you need to add /blog/ in your permalink structure, (unless wordpress is adding that for you). That should be automatic if that is the file it is installed in.

Also, Where is your index.php file for your wordpress install - Is it in the blog folder or in the /public_html/ folder.

If you want to display the blog at http://example.com/blog it should be in the blog folder.

What is the filepath you use to log in? Does that work fine?

like image 93
IanB Avatar answered Oct 15 '22 17:10

IanB