Forum Moderators: phranque

Message Too Old, No Replies

How to avoid 404 error on url with parameters

         

amarillo

10:33 pm on Aug 13, 2011 (gmt 0)

10+ Year Member



Hi,

I have an issue with urls when they have parameters after a question mark. They all give a 404 error. How can I avoid that?

These urls are like that:
website.com/folder/page.html?parameter=1
website.com/folder/page/?parameter=1


My current .htaccess file content is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php


Sincerely,
Amar

g1smd

10:38 pm on Aug 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What happens when you add the required [L] flag to every RewriteRule directive in the .htaccess file?

amarillo

11:01 pm on Aug 13, 2011 (gmt 0)

10+ Year Member



Hello,

Thank you for your reply.

As I'm a total dummy in Apache and .htaccess rules, I don't know what you're talking about.

Sincerely,
Amar

wilderness

12:08 am on Aug 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Apache Flags [httpd.apache.org]

amarillo

9:37 am on Aug 14, 2011 (gmt 0)

10+ Year Member



Hi wilderness,

Thanks for your reply.

I've read the page your recommended and tried to add flags to the rules, it doesn't change the issue or it's worse.

I'm still stuck... :-(

Sincerely,
Amar

wilderness

3:28 pm on Aug 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



code syntax failed.

amarillo

5:51 pm on Aug 14, 2011 (gmt 0)

10+ Year Member



code syntax failed
What do you mean?

wilderness

6:16 pm on Aug 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"flags" are a simple issue to comprehend.

Flags were (and are) even used in DOS-commands, as well as many other software's within Windoze to load programs.

Your simply going to have to review the Apache online links until you you comprehend the use of flags.

There may even be some explanation of flags in the forum library.

FWIW, the "code syntax" comment was for the forum moderators.

lucy24

9:24 pm on Aug 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do your pages actually have query strings? (You said "parameters", but I'm more comfortable with QS and it's the term Apache generally uses, as in [QSA].) If not, you need to find out where they're coming from. If yes, what's supposed to happen to them? Is something in your code saying html when it should be saying php? (or jsp or asp or, or, or...)

Those are the off-the-top-of-my-head questions. You should be asking yourself the same and similar ones.

amarillo

9:05 am on Aug 15, 2011 (gmt 0)

10+ Year Member



Hi Lucy24,

Query strings are coming from another website I work with. I have no control on them, I just need to make sure they don't lead to a 404 error, and that's what they're doing right now. These query strings are used for checking reciprocal links on my pages.

In my website template, I can see I have a file called rewrite.php with lots of redirection rules like those we can find in an .htaccess file but I'm completely clueless... Can I send this file to you and maybe you could tell me what to modify to avoid these 404 errors when a query string is appended ?

Cheers,
Amar

lucy24

3:29 pm on Aug 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, you can't. I'm not saying that to be unhelpful: I just don't speak php.*

First you need to verify that the requests are in fact going to the rewrite.php file, which certainly sounds like where they belong. Spend some time poring over the file. Even if you don't speak php, you should be able to get a general idea of what's happening or not happening. Once you've got it narrowed down a bit, wander next door to the php forum for help with details.


* "Can you speak php?" "I don't know, I've never tried." This approach works fine on my personal site, but I don't recommend it to the world at large.

wilderness

4:27 pm on Aug 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



FWIW, any "Apache settings" in PHP take precedence over htaccess or http.conf

amarillo

5:23 pm on Aug 15, 2011 (gmt 0)

10+ Year Member



Hi,

Thanks for your replies.

Well the *.php is not really full written in PHP.

Apart two basic PHP arrays, all code inside this file is pretty much the same as the code you can find in an .htaccess file:
$rewrites = array(
'#^/top-notes.html$#' => '/site/topNotes',
'#^/top-hits.html$#' => '/site/topHits',
'#^/top-referrers.html$#' => '/site/topReferrers',
'#^/top-rank.html$#' => '/site/topRank',
'#^/top-rank-([0-9]+).html$#' => '/site/topRank/\1',
'#^/(.*)-s([0-9]+).html$#' => '/site/details/\2/\1',
'#^/index.html$#' => '/index.php',
'#^/allcategories.html$#' => '/category/showAll',
'#^/mots-([A-Z0-9]).html$#' => '/keyword/show/\1',
'#^/mots-(.*)-m([0-9]+)-p([0-9]+).html$#' => '/site/keyword/\2/\1/\3',
'#^/tag-(.*)-t([0-9]+)-p([0-9]+).html$#' => '/site/tag/\2/\1/\3',
);

$reverseRewrites = array (
'#^/site/topNotes$#' => '/top-notes.html',
'#^/site/topHits$#' => '/top-hits.html',
'#^/site/topReferrers$#' => '/top-referrers.html',
'#^/site/topRank$#' => '/top-rank.html',
'#^/site/topRank/(.*)$#' => '/top-rank-\1.html',
'#^/site/details/(.*?)/(.*)$#' => '/\2-s\1.html',
'#^/index.php$#' => '/index.html',
'#^/category/showAll$#' => '/allcategories.html',
'#^/keyword/show/(.*)$#' => '/mots-\1.html',
'#^/site/keyword/(.*?)/(.*?)/(.*)$#' => '/mots-\2-m\1-p\3.html',
'#^/site/tag/(.*?)/(.*?)/(.*)$#' => '/tag-\2-t\1-p\3.html',
);

if(Config::get("advancedUrlRewritingEnabled"))
{
$reverseRewrites += array('#^/site/category/(.*?)/(.*?)/1$#' => '/\2/',
'#^/site/category/(.*?)/(.*?)/(.*)$#' => '/\2-p\3/');
}
else
{
$reverseRewrites += array('#^/site/category/(.*)/(.*)/(.*)$#' => '/\2-c\1-p\3.html');
}


This is why I was asking the question.

Regards,
Amar