Forum Moderators: phranque

Message Too Old, No Replies

How to rewrite one page?

Newbie question

         

eager2learnSEO

4:32 am on Aug 27, 2007 (gmt 0)

10+ Year Member



Hello WebmasterWorld:

My apologies for this simple question--I'm pretty new to web development.

I've created a new page on my site that has messy URL: [domain.com...]

I would like to rewrite this URL as either:

1) [domain.com...]

OR

2) [domain.com...]

What code should add to my .htaccess file to implement this rewrite? I can't seem to understand these apache commands for the life of me!

Thanks for your help!

jdMorgan

9:59 pm on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the dynamic (ugly) URL appears on your pages, you'll need to address that first. Modify your script (plugins are available for popular scripts) to produce static-looking URLs, then you can use mod_rewrite to map those pretty URLs, once requested from your server, to the actual (ugly) URLs required to re-invoke the script and produce the requested page.

Mod_rewrite cannot be used to change the URLs that your script outputs; Only the script itself can do that.

Jim

eager2learnSEO

10:10 pm on Aug 27, 2007 (gmt 0)

10+ Year Member



Darn it. So there isn't a way to do a one-off .htaccess modification to make my URL more friendly? I literally need the modification for just one page...

I appreciate the response!

jdMorgan

10:51 pm on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, *you* make the URL 'friendly' on your page, then mod_rewrite can 'reconnect' that friendly URL with the actual (ugly) filepath needed to make your site work.

PHP's preg function is great for beautifying one or all ugly URLs, by the way...

Jim

eager2learnSEO

10:52 pm on Aug 27, 2007 (gmt 0)

10+ Year Member



Got it. Thanks for your help, Jim.

eager2learnSEO

11:53 pm on Aug 27, 2007 (gmt 0)

10+ Year Member



Not to keep beating this horse...

But I spoke to a developer friend and he suggested just adding the following line to my .htaccess:

RewriteRule ^discounts$ template.php?page=4

Anyone see problems with doing this? Thanks everyone.

jdMorgan

12:14 am on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's the correct solution to 'connect' a pretty URL with your script. But that's not the question here.

Jim

eager2learnSEO

4:35 pm on Aug 28, 2007 (gmt 0)

10+ Year Member



Yeah, sorry for not properly framing my question...again, appreciate the help!

jdMorgan

5:43 pm on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> a developer friend

Could this developer friend perhaps assist you in modifying the script that produces the new page's 'ugly' URL? It's just a matter of matching (detecting) the case where that new URL would be produced as a link on the page, and outputting the friendly version instead. Then, as suggested, you add that mod_rewrite code to .htaccess so that when the friendly URL is requested from your server, the server will 'know where to go' to run your script again to generate the content for that page.

It's a two-part process: Modify the link on the page to make it friendly, and then tell Apache what to do when it gets a request for that friendly link.

Jim