Support

Admin Tools

#9910 404 error redirect in .htaccess does not work with apache mod-rewrite enabled for sef

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 Wednesday, 29 June 2011 12:39 CDT

user39319
Mandatory information about my setup:

Have I searched the forum before posting? Yes
Have I read the Troubleshooting Wizard before posting? No
Have I read the documentation before posting? Yes
Joomla! version: (1.5.23)
PHP version: (5.2.13)
MySQL version: (5.0.75)
Host: (optional, but it helps us help you)
Admin Tools Professional version: (2.0.5)

My 404 redirect was working until I enabled SEF and apache mod rewrite in joomlas global configuration. Now the SEF works, but the redirect doesn`t. If I disable the mod rewrite, my redirect works again, but then I lose SEF. Anyway to have both? here is my redirect code:
##### RewriteEngine enabled - BEGIN
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php
##### RewriteEngine enabled - END

rkendallc
Did you add the redirect to an existing .htaccess file? If you did, the problem is that the mod_rewrite changes the URL before it gets to your redirect code. Once it has been processed, your conditions no longer match.

If you want your mod_rewrite and this redirect, you should move this redirect to the top of the file instead of after the SEF code.

This will hold true if you are trying to redirect a domain from .org to a .com extension or domaina.com to domainb.com. They have to be processed before the SEF rules kick in.

user39319
I have that at the very top of my .htaccess file. I used the .htaccess maker in admin tools, and added the redirect in after.

##### RewriteEngine enabled - BEGIN
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php
##### RewriteEngine enabled - END

So where exactly can I place it to make sure its before the sef?

user39319
I have this at the bottom of the .htaccess:

##### Joomla! core SEF Section -- BEGIN
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|raw|ini|zip|json|file|vcf))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##### Joomla! core SEF Section -- END

user39319
any more suggestions?

rkendallc
What you have listed at the bottom as in your previous message is the code to gen the SEF URL's.

What exactly are you attempting to do with your code? Please explain in laymen's terms so that we can have a better grasp of what you are attempting to do.

Could you rename a copy of your htaccess file and attach to a reply, please.

rkendallc
I've asked Nicholas to take a look at this ticket as well since my suggestion did not resolve the issue. It may be a more in-depth htaccess programming issue. He will be able to respond better to it.

user39319
thanks. it will have to wait until monday though, before I can attach the file.

nicholas
Akeeba Staff
Manager
What you are trying to do won't work. The code you are trying to put at the top or the bottom of the .htaccess file is Joomla!'s core SEF section. That already exists in the .htaccess file generated by Admin Tools.

If you place your code on the bottom, it will never be used.

If you place your code on the top of the file, it overrules every protection the .htaccess Maker has to offer.

If you disable mod_rewrite then of course you will get a 500 Internal Server Error as SEF URLs require mod_rewrite for them to work.

From what I see, instead of defining the problem (symptoms) and trying to solve them, you assumed the cause and we were caught in an attempt to help you resolve the assumed cause of the issue. Most likely this will end up with two dozens posts without a result, so let's take a step back, forget everything on this thread and start by defining the problem. Then we will find out the root cause and solve it.

Let's define first what "404 redirection" in your first post means so that there is some context I can work with. Is it a third party component? If so, how it is supposed to work? For example, when someone tries to access a URL which does not exist does it try to log the 404 and redirect it to that component?

Then, let's see the symptoms of the problem. When you enable SEF URLs what happens? What did you expect and what did you get?

Then, let's try to figure out if the .htaccess is to blame or if the problem lies with the 404 redirection component. Remove the .htaccess file generated by Admin Tools, upload the stock htaccess.txt bundled with Joomla! and rename that file to .htaccess. Does the 404 redirection work now?

By providing this information we will be able to know how that redirection was supposed to work, what are the symptoms and where to look for a root cause. Then, we can proceed with triangulating the root cause and solving it :)

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!

user39319
No, I am no using a component. Before I enabled SEF, I was using the code ErrorDocument 404 /index.php in the custom section of the .htaccess maker, and it worked fine. But when I enabled SEF, it stopped. So I tried using the different code above and that still didn't work. I also did what you suggested with the htacces files, and still no go.

nicholas
Akeeba Staff
Manager
This is not a conflict with Admin Tools Professional, it's how Joomla! works. When you enable SEF URLs, Joomla! intercepts all URLs. If it's something non-existent to your site, it throws its own, internal 404 error message. You can either use a SEF component or one of the many 404 error customisation extensions (IIRC Yireo has a nifty one) to customise Joomla!'s 404 page.

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!

user39319
I`ve tried extensions for 404 errors, and the redirects didn`t work then either. sigh. I`ll try again.

user39319
well, everything I try, nothing seems to work, even extensions. I either have SEF urls, or my redirect, nothing lets me have both.

nicholas
Akeeba Staff
Manager
I think that the only way to achieve something like what you want is to use a third-party SEF component (sh404SEF, AceSEF) and create an article to serve as your site's 404 page, as per the component's instructions. This is as far as you can go. As you said, when you enable SEF URLs, your server's customized error pages become irrelevant and won't work. This is due to the nature of SEF URLs. A SEF URL describes a resource which doesn't exist as a file on your site. Your server, therefore, needs to "capture" the 404 errors of the requests to these non-existent resources and forward them to Joomla!. Unfortunately, this will nullify your custom 404 handling.

IMHO, the best approach, SEO-wise, is to enable SEF URLs and don't worry about custom 404 pages too much.

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!