Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a URL rewrite 1

Status
Not open for further replies.

Foamcow

Programmer
Nov 14, 2002
6,092
GB
I'm having trouble getting a simple URL rewrite to work.

My intention is to create some user friendly URLs from the dynamic one's that the site uses to pass parameters to database queries.

I've done this before on other sites and it has worked fine but for some reason it's just not happening with this one.

This is what I have in my .htaccess file

Code:
ErrorDocument 404 /404error.php

php_value session.use_only_cookies 1
php_value session.use_trans_sid 0


Options +All
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domainname\.co.uk
RewriteRule ^(.*)$ [URL unfurl="true"]http://www\.domainname\.co\.uk/$1[/URL] [R=permanent,L]

RewriteRule ^/polyprop$ /product-material.php?material=1 [L]


The problem is with the last line there. The other stuff seems to work fine.
I'm trying to set up a URL rewrite so that users visiting are shown the page at
I've tried a number of things none of which seem to work. The only thing that has worked is a redirect in the form of

Code:
Redirect 301 /polyprop /product-material.php?material=1

but I don't really want to do it this way and would prefer the URL rewrite.

I've also tried commenting out the 404 directive in case this was forcing the showing of the 404 page instead of rewriting the URL.

<honk>*:O)</honk>
Designease Ltd. - polyprop folders, ring binders and creative presentation ideas
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
shouldn't it appear before the first rewrite rule?

Code:
ErrorDocument 404 /404error.php

php_value session.use_only_cookies 1
php_value session.use_trans_sid 0


Options +All
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domainname\.co.uk
RewriteRule ^/polyprop$ /product-material.php?material=1 
RewriteRule ^(.*)$ [URL unfurl="true"]http://www\.domainname\.co\.uk/$1[/URL] [R=permanent,L]
[L]



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Nope, that stops the page loading all together with an error saying that the page isn't redirecting properly.


The first rewrite rule goes with the preceding rewrite condition.

If i put the new rule before the condition then it still just sends me to the 404 page.

If I disable the 404 directive then I get the 'normal' 404 page.

<honk>*:O)</honk>
Designease Ltd. - polyprop folders, ring binders and creative presentation ideas
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
I barely speak enough mod_rewrite to buy a paper, but could it be that you need a RewriteCond as well as a RewriteRule for the second bit?

As far as I can make out, the first rewritey bit says

RewriteCond: Does the domain lack a www. ?
RewriteRule: Take the whole address and 301 it to a URL with the leading www.

Maybe you need a new condition statement to include all addresses, not just non-
I also think that you might not need/want the leading slashes in your rewrite rule, try this:
Code:
RewriteRule ^polyprop$ product-material.php?material=1
With luck, someone may yet post to this thread who knows what he's talking about...


-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks Chris, I'll give it a shot.

But I've done this sort of thing before on a couple of other sites with not problem.

The RewriteCond was something I picked up to avoid the non-www url being used. I've never had to use a rewriteCond before.

I guess this is a bit cargo cult lol, but I really did think that I was getting the hang of this... it seems not!

I'll have another stab at it today.

<honk>*:O)</honk>
Designease Ltd. - polyprop folders, ring binders and creative presentation ideas
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top