Destramic Posted February 1, 2011 Share Posted February 1, 2011 im having a bit of trouble with an expression to reroute my url for instance i want to change my url: news/search/?seach=value and changed to news/search/value here is what i have but its not the correct expression if anyone can help please $routing = array('/news\/search\?(.*?)=(.*?)/' => 'news/search/\2'); thank you [/code] Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/ Share on other sites More sharing options...
Maq Posted February 1, 2011 Share Posted February 1, 2011 Is there a reason you're not using mod_rewrite for this? Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1168430 Share on other sites More sharing options...
Destramic Posted February 1, 2011 Author Share Posted February 1, 2011 Well I thought this would be the right way around things...its for my framework i'm making...but how would I do I mod_rewrite?...and would it be the right way to do things? Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1168503 Share on other sites More sharing options...
Destramic Posted February 3, 2011 Author Share Posted February 3, 2011 After a read mod_rewrite isn't what I need...can anyone help with the regular expression as i'm still having trouble getting it to work...thanks you Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1169637 Share on other sites More sharing options...
.josh Posted February 4, 2011 Share Posted February 4, 2011 $routing = array('~news/search/[^=]+=(.*)~' => 'news/search/$1'); That's just an educated guess, based on what you provided. If it doesn't work, then you need to provide more info. Explain where/how you are getting the URL, the context it coming from, example context, etc... But it looks like (and based on your mention of making a CMS) what you want to do is if user goes to .../news/search/?search=blah you want to redirect to ../news/search/blah well if that is the case, then mod_rewrite is what you should be doing. Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1169675 Share on other sites More sharing options...
Destramic Posted February 4, 2011 Author Share Posted February 4, 2011 well mod_rewrite wont work for what i want...basically when a user submits a form the url will action to news/search/?seach=whatever then i want to re route it by regex then redirect the page to change the url...i dont think i can do that with mod_rewrite making it show the new url and thank you the regex works great thank you...although i changed it slightly and can't get the first $1 to work if you could kindly help again please...than you <?php $pattern = "~news/search/?(.*)+=(.*)~"; $result = "news/search/$1/$2"; $url = "/news/search/?query=test123"; if (preg_match($pattern, $url, $matches)) { print_r($matches); echo preg_replace($pattern, $result, $url); } else { echo "no"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1170040 Share on other sites More sharing options...
.josh Posted February 4, 2011 Share Posted February 4, 2011 well mod_rewrite wont work for what i want...basically when a user submits a form the url will action to news/search/?seach=whatever then i want to re route it by regex then redirect the page to change the url...i dont think i can do that with mod_rewrite making it show the new url That is exactly what mod_rewrite does. Whenever a request is made to your server, regardless of whether a user clicks on a link, submits a form (action="..."), enters url in address bar, clicks a bookmark, etc... it will redirect to specified url. and thank you the regex works great thank you...although i changed it slightly and can't get the first $1 to work if you could kindly help again please...than you You said this was your before: news/search/?seach=value after: news/search/value ...and that's what my regex does.... But now it looks like you are trying to do: before: /news/search/?query=test123 after: /news/search/query/test123 is that what you are trying to do? If so, then it should be: $pattern = "~news/search/\?([^=]+)=(.*)~"; ...but again, I really think you should be using mod_rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1170055 Share on other sites More sharing options...
Destramic Posted February 5, 2011 Author Share Posted February 5, 2011 Thank you for your reply...i tried it with mod rewrite but could get it to redirect to the url I want...could you help on how I could do this?...thanks again for your help Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1170194 Share on other sites More sharing options...
Destramic Posted February 5, 2011 Author Share Posted February 5, 2011 as ive read on here is my attemp but its not working RewriteRule ^news/search/$/$ news/search/?$1=$2 [R] news/search/?fieldname=value to news/search/fieldname/value hope you can help Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1170214 Share on other sites More sharing options...
.josh Posted February 5, 2011 Share Posted February 5, 2011 Okay, you have a link like http://www.yoursite.com/news/search?query=something And you want it to be redirected to http://www.yoursite.com/news/search/query/something Put this in your .htaccess file: .htaccess RewriteEngine on RewriteCond %{QUERY_STRING} ([^=]+)=([^&]*) RewriteRule ^news/search news/search/$1/%2 [R=301] Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1170241 Share on other sites More sharing options...
Destramic Posted February 5, 2011 Author Share Posted February 5, 2011 could get it to work sorry url news/search?field=value to news/search/field/value here is my .htaccess which might help... <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [PT,L] RewriteCond %{QUERY_STRING} ([^=]+)=([^&]*) RewriteRule ^news/search news/search/$1/%2 [R=301] </IfModule> <Files .htaccess> order allow,deny deny from all </Files> sorry to be a pain Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1170272 Share on other sites More sharing options...
Destramic Posted February 8, 2011 Author Share Posted February 8, 2011 can anyone help me please? Quote Link to comment https://forums.phpfreaks.com/topic/226365-expression-help/#findComment-1171476 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.