Forum Topic: Redirect Subdirectory

Forum: .htaccess Forum : Redirecting • Posted by John Harcourt • Updated:

Hi

Just got the book today ....

Quick question if you do not mind.

We have a blog as a subdirectory www.mysite.com/blog ,we do not have a htaccess within that sub-directory .. (should we?)

I cant figure out how to remove the .php from the index page within the blog ...

Its done on the main website ... but cant for the life of me get it done with the subdirectory

I am sure its straight forward, its just I am a little dim :-)

Thanks for your help and the great book, I would have loved to get a hard copy, $30 delivery to Ireland frightened me :-)

Best Regards

John

3 Replies to “Redirect Subdirectory”

Jeff Starr
Posted by Jeff Starr

Hi John,

Absolutely, what are the URL(s) involved specifically (both target and destination) and I'll do my best to help.

For the book, yes shipping is expensive these days, as are most things ;) We may be able to save you some money on shipping if you want to send the zip code to us at https://perishablepress.com/contact/.

Posted by John Harcourt •

Hi Jeff

Thanks for the reply ,apologies for the late reply, I had a rather long weekend ...

I'd rather not post the actual URL but if you need it I happily PM it.

Below is the structure though

URL - www.mywesite.co.uk (contains a htaccess that redirects non www to www and removes index.php file name to avoid duplicate content

I have a blog created within a folder, so the blog is www.mywebsite.co.uk/blog/ This contains an index page ... Which is www.mywebsite.co.uk/blog/index.php

The blog folder does not contain a .htaccess file ..

I have tried adding one to remove the index.php form www.mywebsite.co.uk/blog/index.php ...

As it stands at the moment, the blog can be accessed from

www.mywebsite.co.uk/blog/index.php
www.mywebsite.co.uk/blog

I wish for the www.mywebsite.co.uk/blog/index.php to be redirected to www.mywebsite.co.uk/blog

I hope that makes sense and you can help out

This is what I tried, I created a new .htaccess file and added it to the blog folder, but it didn't work

#Redirect no-www to www
RewriteCond %{HTTP_HOST} !www\.mysite.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [L,R=301]
RewriteRule ^index\.php$ http://www.mysite.co.uk/blog/ [L,R=301]

Thanks again

John

Jeff Starr
Posted by Jeff Starr

Hi John,

How about something like this:

RewriteCond %{HTTP_HOST} ^/blog/index.php$ [NC]
RewriteRule .* http://www.mysite.co.uk/blog/ [L,R=301]

I would first try this before/after existing rules in the root .htaccess file, and then if that doesn't work, add them to .htaccess in the /blog/ directory.

It should work as-is, but some fine-tuning may be required, depending on the actual URL(s).

Let me know how it goes!