Htaccess redirect from sub dir to sub dir/index.php

Hello,
I have the following htaccess and it works

aka were someone to go to mysite.com they would be taken to mysite.com/index.php

#only for the root directory
RewriteCond %{REQUEST_URI} ^/$
#if the uri is not already index.php
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteRule ^$ /index.php    [R=301,L]

My question is, I have directories, were a user to go to the url bar and type

mysite.com/fr/

they get a 404

how can I force users that go to mysite.com/fr/ to be taken to mysite.com/fr/index.php

I have tried the following but it didnt work


#only for the root directory
RewriteCond %{REQUEST_URI} ^/fr/$
#if the uri is not already index.php
RewriteCond %{REQUEST_URI} !^/fr/index.php [NC]
RewriteRule ^$ /fr/index.php    [R=301,L]

thank you for any input

emma

Why do you want to redirect users to index.php ? This will happen by default on most servers.

Thank you
I use permalinks in my multi lingual site. thus. for a french version of my site, I have the same index.php page filtered aka index.php?=3 is permalinked to mysite.com/fr/index.php

now if a user goes direct to mysite.com/fr/index.php, they see the french version of my site, and all looks lovely. but were a user to go to mysite.com/fr/ then wowa nothing happens and they get a 404 as the permalinks do not kick in. thus…I managed to sort it. lol gosh I feel so clever (me joking)

cheers

#only for the root directory
RewriteCond %{REQUEST_URI} ^/$
#if the uri is not already index.php
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteRule ^$ /index.php    [R=301,L]

## created by me, this redirects a user that comes to mysite.com/fr/ to mysite.com/fr/index.php
RewriteRule ^/?fr/.*$^ fr/index.php [R=301,L]
RewriteRule ^/?fr.*$^ fr/index.php [R=301,L]

Oh Blast,
It did work when I tested it many times on firefox, but now I have tested it on chrome I get a 404

what a bummer.

if you have any input I would be grateful, gosh I am really pee d off as I thought I managed it.

I struggle with htaccess rewrite rules I have to say. However, the ^/?fr.*$^ looks unnecessarily complicated. Have you tired something more like /fr/ ?

BTW your browser should affect the result as the .htaccess processing is all on the server.

This isn’t my forte either, so this may be a stupid suggestion, but as it’s only for one URL, can you not just use a permanent redirect?

thanks everyone for help

RewriteRule ^fr/?$ $1/fr/index.php$2 [R=301,L]

the above did the trick haha I cleared out my cache many times and tested on different browsers.

re TechnoBear
Yes I did try that but it got me into other error issues thus. having weighed up my options, lol you know how it is, sometimes you have to do something a little different.

anyway thank you all for you input.

cheers

2 Likes

Thank you Gandalf, I did try that and ended up with /fr/index.php/index.php/index.php/index.php/index.php or something like that anyway. I made a list of what I tried but not of all the errors, when I discovered something didnt work I just swore and tried again. you know how it is.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.