Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite.know the problem but cant find a solution

spaces in urls

         

barryw33

9:00 am on Jun 26, 2008 (gmt 0)

10+ Year Member



hi there,

this is my firts post so a big thank you before I start to anyone willing to help

I am new to mod_rewrite

I have racked my head for days as to why my code wont work...

eureka I have found out why it wont work

now I need a solution

I have a list box with categories in and when the user clicks that it posts back to the same page with the category selection

then lists the first 4 found with a more>> link

the more link is the problem

for example when the user has chosen "All Categories" the url has a space in

the old link would say
<a href="index.php?mode=beinggreen&amp;list=yes&amp;cat=<? echo $cat; ?>&amp;count=<? echo $page; ?>&amp;$keyword=<? echo $keyword; ?>">more&nbsp;></a>

and the url would replace the spaces with %20

the new mod_rewrite code

<a href="index/beinggreen/yes/<? echo $cat; ?>/<? echo $page; ?>/<? echo $keyword; ?>">more&nbsp;></a>

my mod_rewrite code

RewriteRule ^index/([a-z]+)/([a-z]+)/([a-z]+)/([A-Za-z0-9-]+)/([a-z]+)/?$ index.php?mode=$1&list=$2&cat=$3&count=$4&keyword=$5

I know I can get round this by doing a $cat=str_replace(" ","",$cat); and then on reloading the page doing a switch statement replacing the space but the categories come from a db table so when I add a new category I would have to strip the spaces out and add another field and the reference it everytime I reload the page.

So,

is there an easy way around this in mod_rewrite that can solve this problem

Sorry if this post is a bit long winded

many thanks again for any help

barryw33

10:21 am on Jun 26, 2008 (gmt 0)

10+ Year Member



right I have worked it out for myself and here is my solution if anyone wants a workaround...

I don't do anything with the mode_rewrite

line before the link, I str_replace the space for a hyphen

and then on page reload, I str_replace hyphen for space

must remember this when adding new categories...no hyphens

barryw33

10:21 am on Jun 26, 2008 (gmt 0)

10+ Year Member



mod_rewrite not mode_rewrite...doh!

jdMorgan

6:10 pm on Jun 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted!

Jim