Support

Admin Tools

#16195 www to non-www for subdomain redirects to main domain

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 tabletguy on Monday, 27 May 2013 16:10 CDT

tabletguy
Mandatory information about my setup:

Have I read the related troubleshooter articles above before posting (which pages?)? Yes
Have I searched the tickets before posting? Yes
Have I read the documentation before posting (which pages?)? Yes, but not this specific time.
Joomla! version: (unknown) 2.5.11
PHP version: (unknown) 5.3.24
MySQL version: (unknown) 5.1.68-cll
Host: (optional, but it helps us help you) CPanel
Admin Tools version: (unknown) 2.5.5 Pro

Description of my issue:

I have a test site in a subdirectory of 'x62, so the url would be http://mysite.com/x62.
I wanted "http://www.mysite.com/x62/" to go to this also (no 'www').

When I generate an .htaccess file for "www to non-www" it redirects to the main site of http://www.mysite.com and NOT the http://www.mysite.com/x62/

I've also attached a screen shot of the System Settings section of the .htaccess maker, if that is needed.

I believe this is the relevant portion of the .htaccess file. I've changed the actual site name.
--------------
##### RewriteEngine enabled - BEGIN

RewriteEngine On

##### RewriteEngine enabled - END


##### RewriteBase set - BEGIN

RewriteBase /x62

##### RewriteBase set - END


##### File execution order -- BEGIN

DirectoryIndex index.php index.html

##### File execution order -- END


##### No directory listings -- BEGIN

IndexIgnore *

Options All -Indexes

##### No directory listings -- END


##### Redirect index.php to / -- BEGIN

RewriteCond %{THE_REQUEST} !^POST

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/

RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$

RewriteRule ^index\.php$ http%2://mysite.com/x62/ [R,L]

##### Redirect index.php to / -- END

##### Redirect www to non-www -- BEGIN

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]

RewriteRule ^(.*)$ http://%1/$1 [R,L]

##### Redirect www to non-www -- END


##### Rewrite rules to block out some common exploits -- BEGIN

RewriteCond %{QUERY_STRING} proc/self/environ [OR]

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]

RewriteCond %{QUERY_STRING} base64_(en|de)code\(.*\) [OR]

RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]

RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\[0-9A-Z]{0,2}) [OR]

RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\[0-9A-Z]{0,2})

RewriteRule .* index.php [F]

##### Rewrite rules to block out some common exploits -- END

##### File injection protection -- BEGIN

RewriteCond %{REQUEST_METHOD} GET

RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]

RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]

RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC]

RewriteRule .* - [F]

##### File injection protection -- END


##### Advanced server protection rules exceptions -- BEGIN

RewriteRule ^administrator\/components\/com_akeeba\/restore\.php$ - [L]

RewriteRule ^administrator\/components\/com_admintools\/restore\.php$ - [L]

RewriteRule ^administrator\/components\/com_joomlaupdate\/restore\.php$ - [L]

RewriteRule ^templates\/your_template_name_here/ - [L]

##### Advanced server protection rules exceptions -- END

					

nicholas
Akeeba Staff
Manager
You can do that with a redirection rule added to the "Custom .htaccess rules at the top of the file" section of the .htaccess Maker:
RedirectMatch 301 ^/x62/$ http://www.example.com/

where www.example.com is the domain name of your site

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!

tabletguy
Thanks.

First, it appears from reading that that rule does the opposite of what I want? It looks like it redirects anything from mysite.com/x62 to mysite.com This .htaccess file is in the mysite.com/x62 folder. There is a different .htaccess file in the mysite.com root folder.

Also, would this actually redirect anything other than a simple "www.mysite.com/x62/" ? For example, "www.mysite.com/x62/journey/" (to show a category of blog posts"?

I DID have to make an exception in the root folder's .htaccess file, to allow access to the entire "x62" folder to run kickstart.php when I was setting it up, by the way. I hadn't seen that documented anywhere.

Second, are you saying that this isn't a "bug" when setting up an htaccess file? I have other sites that also run from subfolders for other reasons, and I've had problems with them also regarding the www.mysite.com => mysite.com

tabletguy
I verified that the above rule does redirect ALL urls back to the "live" website.

Trying RedirectMatch 301 ^/x62/$ http://mysite.com/x62/ also doesn't work.

BTW, and option to "turn off" or "turn on" the .htaccess file would be useful in testing, as well as a "revert to last good version". Of course, I can do this by keeping Filezilla open at the same time, but it's not as convenient.

Additionally, it appears that I must also TURN OFF the "www to non-www" rule at the same time?

nicholas
Akeeba Staff
Manager
Um, are you trying to redirect FROM the bare domain TO the subdirectory? I think I know how to do it only with two different .htaccess files, one in the main directory and one in the subdirectory. But I don't trust my .htaccess kung-fu enough to suggest a solution without testing it on a real site :( Even worse, I don't know how to combine this with the www to non-www redirection. Sorry!

You can revert the .htaccess. Just remove the .htaccess file and rename the .htaccess.admintools to .htaccess (Admin Tools always copies your previous .htaccess to .htaccess.admintools when you're using the .htaccess Maker feature).

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!

tabletguy
Thanks.

I think I'll just turn that off in the .htaccess maker and turn it on in the SEO component, at least for the test site.

I probably should have made a separate subdomain, but I'm not sure. Looking at the rules of how Apache finds and implements the .htaccess rules http://httpd.apache.org/docs/2.0/howto/htaccess.html (See "How directives are applied"), it's a little scary!

Do you have any favorite tool or website that you use to validate the regex expressions, etc?

##### Redirect www to non-www -- BEGIN
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R,L]
##### Redirect www to non-www -- END


I confess I haven't found the meaning for the %1 in the above rewrite rule. Why isn't it just
RewriteRule ^(.*)$ http://$1 [R,L] since variable '1' is everything AFTER the "www."?

tabletguy
** EDIT **
I wish I could edit the original post here, to have only a single "end of code" marker. It looks ugly! :(

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!