Forum Moderators: phranque

Message Too Old, No Replies

remove url rewriting after a certain point

remove url rewriting after a certain point

         

drooh

8:14 pm on May 1, 2009 (gmt 0)

10+ Year Member



Ok, I must first say i use some basic url rewriting but it is very hard for me to understand.

right now ive got
website.com/our_products/
redirecting to
index.php?page=our_products

the problem is i want to be able to accept

website.com/our_products/?search=true&product_id=1&stuff=this

so in my htaccess file ive tried this but cant seem to get it to work

RewriteRule ^([0-9a-zA-z]+)/$ index.php?page=$1 [NC]

how would i write an exception so that i could accept this?

ive tried this too

rewriteRule ^our_products([^&]*)$ index.phtml?page=our_products$1

jdMorgan

9:08 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Start here: Changing Dynamic URLs to Static URLs [webmasterworld.com]

Jim

drooh

9:34 pm on May 1, 2009 (gmt 0)

10+ Year Member



ive spent all day trying to figure this out and am no where, please help

jdMorgan

9:49 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We can help, but we can't do it for you. We'll happily take specific questions.

All you've told us is "I wrote this code and it doesn't work." That's not highly-useful.

What URL did yo type in?
What result did you expect?
What result did you get?
In as much detail as possible, how did those results differ from your expectations?
Was there anything in your server error log?
Did anything appear incorrect in your server access log?

As for the larger question, please show us a good list of the URLs you want to rewrite -- showing as much variation as possible, so that we can tell which parts of the URLs are fixed, which are variable, and what the acceptable "range" of variation is -- for example, are they numbers? Letters? Upercase and lowercase letters or just lowercase? Mixed letters and numbers? Any hyphens or underscores in them? What about parameter order... Is it fixed or variable. Are some parameters always present in the requested URL, while some may not be there?

You'll get the best answers by providing the information needed to determine the best answers...

Generally, you will need one rule for each possible URL format. You can start with the longest format, get that working, and then remove pieces to create the shorter rules for the shorter formats, or you can go the other way, starting with the shortest format, and building up.

Jim

jdMorgan

10:15 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One more note: You might also want to check out the mod_rewrite documentation, specifically the documentation of the [QSA] flag used with RewriteRule [httpd.apache.org].

That may actually be all that's needed here.

Jim

g1smd

10:33 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure you add [L] to the end of every rule, unless you know exactly why it should be omitted.

Lastly, be clear as to the differences between what a redirect does and what a rewrite does.

That is, in your original question you say you have a redirect, but your code is actually for a rewrite.

drooh

8:59 pm on May 2, 2009 (gmt 0)

10+ Year Member



Ok, let me try to reiterate

im am trying to use .htaccess url rewrite

-the site is displaying products
-after the user searches I want the form to send "get" data instead of "post"

so i need to get a link like this to work

[thewebsite.com...]

id like to re-write it in the following way

index.php?page=products&search=true&id=4

or another way to say this

index.php?page=productss& anything else here

drooh

9:38 pm on May 2, 2009 (gmt 0)

10+ Year Member



i tried this but i still have no clue

rewriteCond %{QUERY_STRinG} ^/?sub=true$
RewriteRule ^our_products/(.*)$/index.phtml?page=our_products&sub=true&$1 [L]

i want everything after /our_products/?sub=true
to be carried over add added onto this
/index.phtml?page=our_products&sub=true

so again
/our_products/?sub=true[everything after]
rewrite to
/index.phtml?page=our_products&sub=true[everything after]

g1smd

10:09 pm on May 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look to the [QSA] flag to do at least a part of what you want to do.

.

The rule can never run, because a Query String would never begin with a / and your pattern is also saying that sub=true is the only query string parameter present (because you both start and end anchored it):

^/?sub=true$

You might try

&?sub=true&?
or similar.

.

Also be aware that the RewriteRule line itself cannot 'see' the query string data, so the (.*) backreference likely doesn't capture what you think it might.

drooh

6:37 am on May 3, 2009 (gmt 0)

10+ Year Member



well i seemed to be able to get this to work somewhat like this
RewriteRule ^our_products/(.*)$ /index.phtml?page=our_products&sub=1&$1 [L,qsappend]

but now some of my images dont show up that are in the same folder?

drooh

7:19 am on May 3, 2009 (gmt 0)

10+ Year Member



also, i have this
RewriteRule ^staff/ index.phtml?page=staff&$1 [L,qsappend]

but none of the images located here are showing up
/staff/img/images.jpg

*edit, i think it was my bad, css in two places, duh...

g1smd

5:43 pm on May 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have likely you have done one or both of two common things:

- used a relative link for the images, so the browser is resolving the URL for those incorrectly,
- not restricted the URL formats that your rewrite responds to, and the image requests are also, incorrectly, being rewritten.

In both of your rules, the $1 usage is likely incorrect, and in one rule there is no way that it could ever work as you never created any backreference.

jdMorgan

9:19 pm on May 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Back-references $1 through $9 refer to the part of the requested URL-path matching the first through ninth parenthesized sub-pattern in the RewriteRule pattern.

Back-references %1-%9 refer to the part of the variable test-string matching the the first through ninth parenthesized sub-pattern of the last-matched RewriteCond pattern.

Jim