Welcome to WebmasterWorld Guest from 54.226.25.231

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod_rewrite problem

How to make dynamic pages appear to have static URLs

     

Jint

1:10 am on Aug 13, 2004 (gmt 0)

10+ Year Member



I working on a new website, and it generates dynamic urls like:
www.domain.com/pagename.php?id=123

but I want the url to be like:
www.domain.com/123/

I've tried this in my .htaccess file, but it gives me a 500 error.

RewriteEngine on
RewriteRule Pattern Substitution [Flag(s)]
RewriteRule /test/([0-9]+) /test/pagename.php?id=$1

Can someone please help me with this? I have tried so many things to get this to work, but still no luck what so ever.

jdMorgan

1:32 am on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Jint,

Welcome to WebmasterWorld!

Here's how this works:

If you want static-appearing URLs like www.domain.com/123/, you must modify your script to produce them. Users and search engine spiders will then pick up these static-appearing URLs, and request them from your site.

Then, when your server receives a request for a static URL, your use mod_rewrite to convert that static URL to the dynamic form needed to call your script.

Mod_rewrite works after a request is received by your server, but before any scripts are invoked and before any content is served. Mod_rewrite cannot be used to change the URLs output by your scripts or those present in static html pages. Therefore, the normal use of mod_rewrite may seem "backwards" from what you expected.

See our Apache forum charter for links to Apache and mod_rewrite resources.

Jim

Jint

12:06 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



When I used a rewriterule generator from an online webmaster toolkit, I got the rewrite rule:

Options +FollowSymLinks
RewriteEngine on
RewriteRule pagename/(.*)/(.*)/$ /pagename.php?$1=$2

which gives me the url:

www.domain.com/pagename/id/123/

Shouldn't it then be quite easy to get rid of the

pagename/id/

part?

[edited by: jdMorgan at 1:31 pm (utc) on Aug. 13, 2004]
[edit reason] Removed specifics per TOS [/edit]

JasonHamilton

12:56 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



RewriteRule pagename/(.*)/(.*)/$ /pagename.php?$1=$2

which gives me the url:

www.domain.com/pagename/id/123/

Shouldn't it then be quite easy to get rid of the

Yes.

There isn't any reason for the "id" being passed, as it is static.

RewriteRule page/(.*)/$ /page.php?id=$1

Then you can have:

www.domain.com/page/123/

Jint

1:45 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



Now I have this in my .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule pagename/(.*)/$ /pagename.php?id=$1

Located at: domain.com/test/

but it returnes a 404 error when I go to the address:

www.domain.com/test/pagename/123/

www.domain.com/test/pagename.php?id=123 still works...

 

Featured Threads

Hot Threads This Week

Hot Threads This Month