code_junkie

apache mod_rewrite one rule for any number of possibilities

Nov 11th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. RewriteRule ^([a-z]+)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?mode=$1&id=$2&$3=$4&$5=$6
  2. RewriteRule ^([a-z]+)/([^/]*)/([^/]*)/([^/]*)$ /index.php?mode=$1&id=$2&$3=$4
  3. RewriteRule ^([a-z]+)/([^/]*)$ /index.php?mode=$1&id=$2
  4. RewriteRule ^([a-z]+)$ /index.php?mode=$1
  5.  
  6. http://www.domain.com/search
  7. http://www.domain.com/search/3039/sort_by/name_asc/page/23
  8.  
  9. RewriteCond %{REQUEST_FILENAME} !-f
  10. RewriteCond %{REQUEST_FILENAME} !-d
  11. RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
  12.  
  13. RewriteBase /
  14. RewriteCond %{REQUEST_FILENAME} !-f
  15. RewriteCond %{REQUEST_FILENAME} !-d
  16. RewriteRule . /index.php [L]
  17.  
  18. $path = split('/', $_SERVER['REQUEST_URI']);
  19. array_shift($path); // We always have a first null value
  20. $mode = array_shift($path);
  21.  
  22. http://example.com/foo/bar/baz
  23.  
  24. RewriteCond %{QUERY_STRING} ^(.*)$
  25.  
  26. RewriteCond %{QUERY_STRING} ^(.*)$
  27. RewriteRule ^(.*/)([^/]+)/([^/]+) $1?$2=$3&%1 [L]
  28. RewriteCond %{QUERY_STRING} ^(.*)$
  29. RewriteRule ^([^/]+)/ $1.php?%1 [L]
  30.  
  31. /mypage/param1/val1/param2/val2/param3/val3/... --->
  32. /mypage.php?param1=val1&param2=val2&param3=val3&...
Add Comment
Please, Sign In to add comment