Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-07-27 01:00:07
- titilayo
- New Member
- Registered: 2006-07-25
- Posts: 9
avoid displaying home page when files/directories are missing
When someone comes to my site via a link to a page that’s no longer there (the file/directory has been removed), they automatically end up on my index page (but the URL for the missing file/directory remains in the address bar). I gather that this has to do with this line in the .htaccess file
<code>RewriteRule ^(.*) index.php</code>
The thing is that I’d prefer to serve visitors some sort of error message rather than having them sent straight to the index page. I tried posting a custom error page and using the standard method for specifying it. Also I tried replacing index.php in the above code with the name of the error page but that didn’t quite work the way I wanted (I began getting errors for links to the home page that didn’t use include /index.php), and I guess that’s because the line there isn’t strictly speaking a simple redirect?
Basically my question is, what can I do to serve my visitors an error page instead of having them sent automatically to index.php? Any suggestions? I’m using messy URLs, if that makes it any simpler.
Thanks!
Last edited by titilayo (2006-07-27 01:01:52)
Offline
#2 2006-07-27 01:38:45
- zem
- Developer Emeritus

- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: avoid displaying home page when files/directories are missing
Textpattern should handle 404 errors correctly. Can you give us an example of a URL that does this?
Alex
Offline
#3 2006-07-27 01:47:36
- titilayo
- New Member
- Registered: 2006-07-25
- Posts: 9
Re: avoid displaying home page when files/directories are missing
here’s one . Really, just about every URL associated with my old set-up (I scrapped the entire directory structure for that site) does, so everyone coming to my site from a search engine or external link gets redirected to my homepage with explanation.
Offline
#4 2006-07-27 05:15:16
- zem
- Developer Emeritus

- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: avoid displaying home page when files/directories are missing
I’ve moved this to Troubleshooting. Can you post your diagnostics please?
Alex
Offline
#5 2006-07-27 09:08:25
- titilayo
- New Member
- Registered: 2006-07-25
- Posts: 9
Re: avoid displaying home page when files/directories are missing
I wasn’t sure when I first posted it which was the best place for it, so thanks for moving it. My diagnostics are below. I’m getting the error about register_globals, but if I turn it off, I get a 500 error, so I’m just leaving it on.
<code>ast Update: 2006-07-22 00:44:40/2006-07-24 16:49:59
Document root: /home/gallimau/public_html
$path_to_site: /home/gallimau/public_html
Textpattern path: /home/gallimau/public_html/textpattern
Permanent link mode: messy
Temp folder: /home/gallimau/public_html/textpattern/tmp
Site URL: www.gallimaufry.ws
PHP version: 5.0.4
Register globals: 1
Server Local Time: 2006-07-27 04:06:12
MySQL: 4.0.25-standard-log
Locale: en_GB.UTF-8
Server:
PHP Server API: cgi
Server OS: Linux 2.4.21-15.0.3.EL
Pre-flight check:
————————————
Your version of PHP has security related risks. Please turn register_globals off or update to a newer PHP version.
————————————
.htaccess file contents:
————————————
DirectoryIndex index.php index.html
#Options +FollowSymLinks
#RewriteBase /relative/web/path/
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+) – [PT,L]
RewriteRule ^(.*) index.php </IfModule>#php_value register_globals 0
ErrorDocument 404 http://www.gallimaufry.ws/error.html
————————————
</code>
Offline
Re: avoid displaying home page when files/directories are missing
Are you using any plugins that do anything with urls? Like add new url-formats, add rewrites or anything like that? Tere’s also a logging-plugin which does redirects on 404 IIRC.
Because out of the box, textpattern handles 404s by sending a proper 404-header and showing the defined error-page (the page defined in textpattern: error_404 if available, or else error_default). If you wanted to have an automatic redirect (301/302) in place of the 404, you would have to add that code in your 404-page-template.
My guess is that you are usin a plugin that is overriding this behaviour. Try turning off all plugins.
Offline
#7 2006-07-27 10:04:43
- titilayo
- New Member
- Registered: 2006-07-25
- Posts: 9
Re: avoid displaying home page when files/directories are missing
I have no plug-ins whatsover. I’m using textpattern just as it comes in the download, no hacks, no plug-ins, no extras at all. If I a link to, for example, a textpattern section that doesn’t exist, I get the standard txp error page, see? But any links to sites from my old directory structure do the redirect thing.
Last edited by titilayo (2006-07-27 10:55:57)
Offline
#8 2006-07-27 11:39:36
- zem
- Developer Emeritus

- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: avoid displaying home page when files/directories are missing
Ah, I think I see. You’re using messy URL mode, but have the .htaccess rewrite rules installed and working.
If you either switch to clean URL mode, or remove the rewrite rules, I think you’ll find the problem goes away.
Alex
Offline
#9 2006-07-27 12:26:32
- titilayo
- New Member
- Registered: 2006-07-25
- Posts: 9
Re: avoid displaying home page when files/directories are missing
Worked like a charm! Thank you so much.
Offline