Welcome to WebmasterWorld Guest from 54.159.19.75

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite not working, not sure why.

Is what I am trying to do even possible?

     
4:04 am on Sep 23, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 2, 2005
posts:505
votes: 0


Current url:
page.php?result=resultnamehere

I want it to be:
page_result.html

Here is what I am placing in my htaccess, but it isn't working.

RewriteRule ^([^./]+)\.html$ page.php?result=$1&%{QUERY_STRING} [NC,L]

I have tried other methods that worked fine. But currently, I have one of the pages already posted, but it's static. I'd like to make it's counter-part pages have a similar URL structure, if possible.

5:23 pm on Sept 23, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The links ON the page need to point to the www.domain.com/page_result.html URL.

The rewrite then translates the requested URL into the internal filepath to get the content from.

2:43 am on Sept 26, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 2, 2005
posts:505
votes: 0


They are already linked.
And anyway, a proper rewrite should work simply by typing the re-written URL into my browser's address bar.
I am getting a 404.

I mis typed my initial rewrite, this is what I am actually using:

RewriteRule ^page_([^./]+)\.html$ page.php?result=$1&%{QUERY_STRING} [NC,L]
6:37 am on Sept 26, 2007 (gmt 0)

Junior Member from US 

10+ Year Member

joined:Nov 30, 2002
posts:162
votes: 0


Give this a try:

RewriteRule ^page_([a-zA-Z0-9]+)\.html$ page.php?result=$1 [L]

Does that work?

1:54 pm on Sept 26, 2007 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


> And anyway, a proper rewrite should work simply by typing the re-written URL into my browser's address bar.

Not quite. As g1smd says, you must put a link to page_result.html on your Web pages. This defines the URL for all the world to use.

Then mod_rewrite is used to detect requests for that URL, and rewrite them to page.php?result=resultnamehere so that your page.php script is invoked to produce the desired page.

mod_rewrite cannot change a URL; It can only "reconnect" a search-engine-friendly static URL with the script needed to produce the content for that friendly URL.

If you do not change the links on your pages, then your only option is to use 301-Moved Permanently redirects on every 'unfriendly' URL request to redirect the requests to the friendly URL. This involves an additional HTTP transaction per request, and therefor doubles your server load (for those URLs) and slows the visitor experience. Once the redirect is accomplished, you once again have to use an internal rewrite to provide content for the now-friendly requested URLs. So the bottom line is that the links on a page define the URLs that the world uses, and that mod_rewrite cannot change those on-page URLs except by using an external redirect -- Which is neither efficient nor 'transparent'.

Jim

2:31 am on Sept 29, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 2, 2005
posts:505
votes: 0


I added the link, as g1smd suggested and I still get a 404.

> And anyway, a proper rewrite should work simply by typing the re-written URL into my browser's address bar.

Not quite. As g1smd says, you must put a link to page_result.html on your Web pages. This defines the URL for all the world to use.


Say somebody clicked a link to this page in google instead of following it from my internal website structure. Wouldn't this essentially be the same thing as typing the URL into my browser's address bar?

upside, I tried your rewrite and no luck.

Is this type of rewrite only possible in this fashion:

RewriteRule ^page/([^.]+)\.html$ page.php?result=$1&%{QUERY_STRING} [NC,L]

..because if I use the above rewrite, it works fine.