homepage Welcome to WebmasterWorld Guest from 54.196.197.153
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewrite not working, not sure why.
Is what I am trying to do even possible?
jake66




msg:3458414
 4:04 am on Sep 23, 2007 (gmt 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.

 

g1smd




msg:3458672
 5:23 pm on Sep 23, 2007 (gmt 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.

jake66




msg:3461012
 2:43 am on Sep 26, 2007 (gmt 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]

upside




msg:3461129
 6:37 am on Sep 26, 2007 (gmt 0)

Give this a try:

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

Does that work?

jdMorgan




msg:3461443
 1:54 pm on Sep 26, 2007 (gmt 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

jake66




msg:3464350
 2:31 am on Sep 29, 2007 (gmt 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.

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved