Solved

Need .htaccess expression to trap missing pages

Posted on 2012-03-21
7
308 Views
Last Modified: 2012-08-14
Hello Brilliant Ones!

ATTENTION: I need an mod_rewrite PRO, I will pay you. Greg 210 493 6193

I need an .htaccess expression to trap missing pages.

I'm using this currently in Joomla:

########## Begin - Joomla! core SEF Section
# My extra line below to direct any .htm pages to page.php (working)
RewriteRule ^([^/]*)\.htm$ /page.php?str=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section

# In these lines I want to trap ANY remaining NOT found files, and direct to page.php with including the name sent to [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*) /page.php?str=$1 [L]   (not working, gets 404)


I know I have 2 lines of;
RewriteCond %{REQUEST_FILENAME} !-f

I don't know how to make this work...

Thanks, Greg
0
Comment
Question by:gregsschipper
  • 3
  • 3
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37751857
# did you use this as last rule?
RewriteRule ^([^/]*) /page.php?str=$1 [L]

# if so, you may try
RewriteRule ^([^/]*)$ /page.php?str=$1 [L]
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37752618
I do not use Joomla, so I do not know if this will work for you but it works for me and you might be able to test it fairly easily,  Here is my .htaccess:
ErrorDocument 404 /404handler.php

Open in new window

And here is my 404handler script:
<?php // 404handler.php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('log_errors', TRUE);
session_start();

if (isset($_SERVER["REQUEST_URI"]))
{
    // LOG THE ERROR
    error_log('404: ' . $_SERVER["REQUEST_URI"]);

    // SAVE THE REQUEST
    $_SESSION["REQUEST_URI"] = $_SERVER["REQUEST_URI"];

    // IF A PHP SCRIPT IS NOT FOUND GO TO THE HOME PAGE
    if (preg_match('#\.php#i', $_SERVER["REQUEST_URI"]))
    {
        header("HTTP/1.0 404 Not Found");
        header('Location: /');
        exit;
    }

    // IF A NON-PHP SCRIPT IS NOT FOUND, TRY IT WITH PHP
    $arr = explode('?', $_SERVER["REQUEST_URI"]);
    $arr[0] .= '.php';
    $uri = implode('?', $arr);
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $uri");
    exit;
}

// IF NO REQUEST URI
header("HTTP/1.0 404 Not Found");
header('Location: /');
exit;

Open in new window

HTH, ~Ray
0
 

Accepted Solution

by:
gregsschipper earned 0 total points
ID: 37752880
Thanks Guys.
I found an answer by another means, it is:
RewriteRule ^r/([^/]*)$ /page.php?str=$1 [L]
Many Thanks, Greg
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 37752898
where is the r/ comming from? you never mentioned it before ...
0
 

Author Comment

by:gregsschipper
ID: 37753720
If I use the r/ it doesn't interfere with Joomla functionality!
Thx Greg
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37754888
so you rewriting only URLs which contain r/ now, that was not your question, just wondering ...
0
 

Author Closing Comment

by:gregsschipper
ID: 37770389
I found a solution elsewhere.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now