Support

Admin Tools

#10069 htaccess — Joomla in a subfolder ?

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by nicholas on Thursday, 20 October 2011 08:59 CDT

Chacapamac
Mandatory information about my setup:

Have I read the related troubleshooter articles above before posting (which pages?)? Yes
Have I searched the forum before posting? Yes
Have I read the documentation before posting (which pages?)? Yes
Joomla! version: (1.5.24)
PHP version: (5+)
MySQL version: (5+)
Host: (optional, but it helps us help you)
Admin Tools version: (last)


Description of my issue:

I see that you participate in the Joomla htaccess at
Your text to link here...

Some of my sites ask for joomla to be in a subfolder of the public root (Public_html or web) and I search for a long time (Years) to have a nice 301 permanent redirect for that type of situation without any success — I always end up with a temporary redirect.

Do you think the htaccess maker can help me for that or do you have a solution?

Thanks in advance

AdminPro version

nicholas
Akeeba Staff
Manager
Hi!

The .htaccess mentioned in the Joomla! wiki is actually a very old version of my Master .htaccess. My Master .htaccess is also the base upon which the .htaccess Maker feature in Admin Tools Professional was built. The whole idea came from a discussion over coffee I had with JoomlaWorks' owner (of K2 fame), Fotis, over the need of a GUI tool to configure that huge file :)

Now, regarding your problem, let me see if I understand this correctly. You have Joomla! in a subdirectory, let's say /site, in your server. However, you want is someone visits, say http://www.example.com/foobar.html to be redirected to http://www.example.com/site/foobar.html. Correct? In this case, you don't need a .htaccess in the Joomla! site, you just need a .htaccess in the root of the site which will forward all URLs to the subsite using the [R=301] flag in the redirection line. I could write one such file for you if you can't do it yourself.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Chacapamac
I see.

The htaccess maker is for the htaccess in Jommla — I should realized that — This is obvious — Sorry.

Now, it can’t help to do an external htaccess (if Joomla is in a subfolder)

Root —> subfolder —> joomla files (+ internal htaccess)

Nicholas, this is years that I try to have a decent/efficient 301 redirect and clean SEF url (without the subfolder name).

I’m ready to pay for your time if you do this, that will be fantastic....

Question: Even if I have an external htaccess can I still use the htaccess maker for the security and avantages it give — Without using the redirection feature?

nicholas
Akeeba Staff
Manager
Let's see... The security enhanced .htaccess should be in exactly one place: your Joomla! site's directory. This means that your setup is just fine. Your problem, as I understand it, is because Joomla! is in a subdirectory you get URLs like http://www.example.com/site/something.html whereas you's like to have URLs like http://www.example.com/something.html.

In order to do that, you have to move your entire Joomla! site from the subdirectory to the web root. There are no shortcuts to that. While you could rewrite the URLs not to use the subdirectory name, this would cause severe operating issues with Joomla!, not only with SEF URLs but, most importantly, with serving images, CSS and Javascript.

To cut a long story short, you seem to be trying to solve the correct problem in the wrong way, sort of trying to do it backwards than you should :)

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Chacapamac
Under certain condition I have no choice to do so (Having a subfolder)
I already have good, clean Url, without the subfolder name
My root htacces is:
# Use PHP5CGI as default
AddHandler fcgid-script .php
# AddHandler application/x-httpd-php5s .php

# Bluehost.com
# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.

RewriteEngine on

# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?YOURSITENAME.com$ [NC]

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/YOURSUBFOLDERNAME/

# Don't change these lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /YOURSUBFOLDERNAME/$1 [L]

# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?YOURSITENAME.com$ [NC]
RewriteRule ^(/)?$ YOURSUBFOLDERNAME/index.php [L]


<Files 403.shtml>
order allow,deny
allow from all
</Files>


Note: I use the mod rewrite to erase the subfolder from the url

The joomla htaccess (inside subfolder) stay like the original (only little addition for security and performance. (no
# RewriteBase /
)

My configuration.php have
var $live_site = 'http://www.YOURSITENAME.com';



Everything is rosy with SEF and google verification and all. But, I think this give me 302 redirect, I’m not sure.
I really want to have 301

nicholas
Akeeba Staff
Manager
OK, now it's crystal clear what you're doing. Yes, you are doing a 302 redirect. In order to do a 301 redirect you can change this line:
RewriteRule ^(.*)$ /YOURSUBFOLDERNAME/$1 [L]
to
RewriteRule ^(.*)$ /YOURSUBFOLDERNAME/$1 [L,R=301]
If you have Apache 2.2 then this will work and you'll have a 301 redirection. However, if you have an older version of Apache, this won't work. Moreover, please note that doing a 301 redirection may kill your HTML forms. Well, your mileage may vary :)

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!