homepage Welcome to WebmasterWorld Guest from 54.196.24.103
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod_rewrite problem
How to make dynamic pages appear to have static URLs
Jint




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

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




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

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




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

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




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

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




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

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...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved