Forum Moderators: phranque

Message Too Old, No Replies

Rewriting Ugly URLs

Question about rewrite rules for ugly php urls

         

adriayna

1:57 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



Hi everyone,

I've been pulling my hair out of my head for two days trying to figure out why this rewrite rule isn't working.

I'm trying to redirect a URL that looks like this:

[domain.edu...]
and

to something like this:

[domain.edu...]

Here is the rewrite rule I currently have which is not working:

------------

Options FollowSymLinks
RewriteEngine on

RewriteRule ^resource/([0-9]+)/([0-9]+)([/]?)$ /resource.php?article=$1&page=$2 [L]

------------
I have the .htaccess file in the top level of the "engagement" directory (we run a lot of specialty areas on the site and each one has their own htaccess file). Other rewrite rules in other directories work fine with this setup.

Can anyone tell me what I'm doing wrong? Thank you so much for your help--it is appreciated :).

jdMorgan

10:07 pm on Jun 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, what happens with that rule in place? -- What goes wrong? What do you see in your browser? What do you see in your access log? What do you see in your server error log? How do your results differ from your expectations?

Did you completely flush your browser cache before testing?

Your rule rewrites a client request (a click on an on-page link) for http://example.com/engagement/2/1/ to the server-internal filepath /engagement/resource.php?article=2&page=1
It appears to be correct, except that the final subpattern "([/]?)" could be equivalently coded as just "/?" without any change in function.

This code does not change the link on the page, or change the URL that appears in the browser address bar; Only changing (editing) the link on the page (or modifying the script that produces the page and the links on it) can do that. What this code does is "associate" the /engagement/2/1/ URL with the server filepath of the script that "handles" that URL, and convert the URL to the form needed to call your script.

Jim