Google test works, redirects work, Friendly URLs FAIL!

Discuss practical ways rearrange URLs using mod_rewrite.

Google test works, redirects work, Friendly URLs FAIL!

Postby danp84 » Wed Apr 30, 2008 6:47 pm

So I have used the "Google test" to confirm that mod_rewrite is enabled. That works.

I generally can do redirects from missing files and other similar redirects. Again, that works.

But where I completely fall apart is with Friendly URLs. Absolutely nothing happens when I use the seemingly simple code such as what follows:

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^test/([0-9]+)$ testpage.php?id=$1 [QSA,L]


I have tried the code above with and without the slash in front of testpage.php, but absolutely nothing happens in either case. I believe all of the required settings are enabled, but I do not get the desired output which is a friendly link in the format:

http://www.mydomain.com/test/1

from the URL:

http://www.mydomain.com/testpage.php?id=1

Can anyone help?
danp84
 
Posts: 6
Joined: Wed Apr 30, 2008 12:51 pm

Postby richardk » Thu May 01, 2008 1:19 pm

What happens when you go to /test/1? Mod_rewrite does not change the links in your pages.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby danp84 » Fri May 02, 2008 12:41 pm

Ok, very interesting. If I manually type in:

http://www.mydomain.com/test/1

I see the requested page. So I can confirm what I put in works.

But I thought that mod_rewrite would allow a user to enter or click on an an "unfriendly" URL and the "friendly" URL would be shown in the address bar as a mask or after a redirection. Is that possible? If so, what would be the required script?
danp84
 
Posts: 6
Joined: Wed Apr 30, 2008 12:51 pm

Postby richardk » Sat May 03, 2008 4:21 pm

You should be changing all the links in your pages. For links you cannot control you can redirect the user to the new URL
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?id=([0-9]+)(&.*)?$ [NC]
RewriteRule ^testpage\.php$ /test/%2/? [R=301,L]

RewriteRule ^test/([0-9]+)/?$ testpage.php?id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby danp84 » Tue May 06, 2008 10:08 am

Great! I confirmed the code works!

Thanks a lot!
danp84
 
Posts: 6
Joined: Wed Apr 30, 2008 12:51 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 82 guests

cron