Forum Moderators: phranque

Message Too Old, No Replies

htaccess mod rewrite 404 error

         

jshpik1

3:36 pm on Feb 15, 2010 (gmt 0)

10+ Year Member



I keep getting a 404 error and I'm not sure why. Here's the code in my .htaccess:


<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteRule lyrics/a/page/(.*)$ lyrics/a/\?current_page=$1[L]
</ifmodule>


Thanks for the help!

jdMorgan

6:36 pm on Feb 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dump the <IfModule> container unless you require this code to fail silently when mod_rewrite is not available.

Start anchor the RewriteRule pattern, unless you want to match "lyrics/a/page/<anything>" preceded by any number of any characters, filepath-parts, or directory-paths.

Do not escape the question mark in the substitution URL.

Observe required mod_rewrite syntax precisely; You are missing a space ahead of [L].

I recommend a thorough read of the mod_rewrite docs at apache.org before use. Failing to do that can be close to suicide. More resources are cited in our Apache Forum Charter.

Jim

jshpik1

12:08 pm on Feb 17, 2010 (gmt 0)

10+ Year Member



What I need to do is:

RewriteRule ^lyrics/a/(.*)$ lyrics/a/?current_page=$1 [L]

However I keep getting a 500 server error.

Why would I not get a server error with:

RewriteRule ^lyrics/a/page/(.*)$ lyrics/a/?current_page=$1 [L]

I've also tried:

RewriteRule ^lyrics/a/([0-9][0-9])$ lyrics/a/?current_page=$1 [L]

I do not get a server error however I still get the 404 error. The links can be lyrics/a/(numbers 1 - 99) which is what I need to point to the corresponding php code link.

Examples: lyrics/a/2 needs to point to lyrics/a/?current_page=2, lyrics/a/3 needs to point to lyrics/a/?current_page=3, lyrics/a/25 needs to point to lyrics/a/?current_page=25

[edited by: jshpik1 at 12:27 pm (utc) on Feb 17, 2010]

jshpik1

12:09 pm on Feb 17, 2010 (gmt 0)

10+ Year Member



What I need to do is:

RewriteRule ^lyrics/a/(.*)$ lyrics/a/?current_page=$1 [L]

However I keep getting a 500 server error.

Why would I not get a server error with:

RewriteRule ^lyrics/a/page/(.*)$ lyrics/a/?current_page=$1 [L]

I've also tried:

RewriteRule ^lyrics/a/([0-9][0-9])$ lyrics/a/?current_page=$1 [L]

I do not get a server error however I still get the 404 error. The links can be lyrics/a/(numbers 1 - 99) which is what I need to point to the corresponding php code link.

*** PLEASE DELETE THIS REPLY ***

g1smd

12:28 pm on Feb 17, 2010 (gmt 0)

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



RewriteRule ^lyrics/a/(.*)$ lyrics/a/?current_page=$1 [L]


This will rewrite to itself in an infinite loop.

Change the (.*) to (.+) so that the extra characters are 'required', not 'optional'.

That's why the one with 'page' works, it has additional characters.

jshpik1

2:06 pm on Feb 17, 2010 (gmt 0)

10+ Year Member



I did what you suggested and I'm not getting the 500 error, but I'm still getting a 404. How do I make it so that the numbers are the same like:

RewriteRule ^lyrics/a/(x number)$ lyrics/a/?current_page=(x number)$1 [L]

Right now it looks like:

RewriteRule ^lyrics/a/(.+)$ lyrics/a/?current_page=$1 [L]

jdMorgan

2:25 pm on Feb 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would be helpful to you (and likely to us) if you would report the error message in your server error log.
The access log will show you the requested URL. The error log will show you the (probalby-incorrect) filepath that that URL is being rewritten to.

"/lyrics/a/" must be a path that resolves to a script which accepts the "current_page" query string. If this filepath association for "/lyrics/a/" is not defined using DirectoryIndex, then it won't resolve, and you'll get a 404. I assume that you'd want to point it to "/lyrics/a/index.php" or similar. If you wish to 'share' the script among (again, guessing here) /lyrics/a/ and /lyrics/b/ etc., then you'll likely want to define the DirectoryIndex as a script in your top-level directory or use another rewriterule to "map" all these "letter" subdirectory index requests to the script in your top-level directory.

Jim