• PHP Help General Help
  • [RESOLVED] problem with htaccess rewrite capturing url sections that may or may not be there ..

Hi

I've got a bit of a problem with my url rewrites as I need to capture 3 chunks of the url string and turn them into get variables - however the 2nd and 3rd chunks may not exist in which case I need to still "capture" them as an empty value

This ONLY applies to urls with the string "action/" - all the others just have ".php" tagged on the end to get the right file

so, for example, I could have

http://mydoman.com/action/firstchunk
http://mydoman.com/action/firstchunk/secondchunk
http://mydoman.com/action/firstchunk?third=chunk&stillthird=chunk
http://mydoman.com/action/firstchunk/secondchunk?third=chunk

this then needs to be rewritten as

http://mydomain.com/task.php?t=firstchunk&v=secondchunk & the GET vars in the third chunk, if any

This is quite seriously doing my head in as I've got a rewrite that works fine without the original url query string GET vars but I just can't figure out how to add them on to the rewrite

can any help, please ??

here's my htaccess so far :

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# redirect the url with www to url without
RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?mydomain\.(?:fr|co\.uk))$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule action/([^/]*)/?([^/]*)$ task\.php?t_id=$1&v_id=$2 [NC]

# add .php to urls
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

ErrorDocument 404 /404.php

    Ah man, this has done my head in so much

    I even had this

    \/action\/([0-9a-zA-Z-_]+)\/?([0-9a-zA-Z-_]*)\??(.*)$

    which seemed to work ok capturing the chunks but in the context of the site it just wasn't sending the GET vars, or something

    While I was looking at that I realised that although the server rewrites to the new page it still sends the original $_SERVER['REQUEST_URI'] from which I can extract the different parts of the string - it's somewhat clunky ... but works !

    Thanks to anyone who took the time to read my problem

      Write a Reply...