Xeoncross Posted August 31, 2007 Share Posted August 31, 2007 I was just wondering if I could take some URL like http://site.com/plugin/tumblelog/2/title/date and turn it into site.com/index.php?page=plugin&type=tumblelog&page=2&data=title/date Now the problem is, I am building this for a system and I wan to make it so that the end stuff (page/title/date) is optional. For example these URL's should also work with the same rule: http://site.com/plugin/tumblelog/, or http://site.com/plugin/tumblelog/5/order/CAP So I have tried this but it doesn't work. Code: RewriteRule ^plugin/([A-Za-z0-9\-]+)/(.*/)?(.*/)*$ index.php?page=plugin&type=$1&page=$2data=$3 [L] or RewriteRule ^plugin/([A-Za-z0-9\-]+)/(.*/)*$ index.php?page=plugin&type=$1&data=$2 [L] Lets say that the above does work and I pass this URL: http://site.com/plugin/tumblelog/5/order/CAP Then I was thinking of using some PHP like this to get the data: <?php $page_data = explode('/', $_GET['data']); /* $page_data[0] = '5'; $page_data[1] = 'order'; $page_data[2] = 'CAP'; */ ?> So, can you make parts of the rewrite optional in mod_rewrite? So that I could have (or not have) the end data like "page/title/count" and it wont affect the rewrite? Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted August 31, 2007 Author Share Posted August 31, 2007 Ok, that last post was a little confusing So how about this: I want to know if this code will redirect correctly RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+/)?(.*/)?(page_([0-9]+)/)?$ index.php?page=$1&type=$2&data=$3¤t_page=$4 [NC,L] #Examples: # page=tag / life/ (nodata/) page_10/ # page=post / blog/ (id/title/) page_1/ # page=plugin / tumblelog/ (order_by/) page_3/ URL's that would need to be directed: http://site.com/tag/life/page_21 <TO> /index.php?page=tag&type=life&data=¤t_page=21 http://site.com/tag/page_1 <TO> /index.php?page=tag&type=&data=¤t_page=1 http://site.com/post/articles/45/title_of_post/page_1 <TO> /index.php?page=post&type=articles&data=45/title_of_post?current_page=1 http://site.com/plugin/newsreader/page_5 <TO> /index.php?page=plugin&type=newsreader&data=?current_page=5 Is my HTACCESS code right? I guess that after I rewrite the whole system I will know - but I would like to know before hand if there are errors in my logic or code. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted September 1, 2007 Share Posted September 1, 2007 You are writing a static URLs to dynamic URLs? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.