Lukeidiot Posted January 17, 2014 Share Posted January 17, 2014 Hello, I seem to having an issue figuring out the right mix of regex here. ---------------------------------------------first-------------------------------------------------------second----------------------------------------------- url.rewrite-once = ( "^/sc5/([^.?]*)$" => "/sc5/index.php?go=$1", "^/sc5/view/(.*)" => "/sc5/view/index.php?i=$1" ) The first mod_rewrite makes my url clean by changing example.com/?go=test to example.com/test The second mod_rewrite (IS SUPPOSED) to make the same thing happen, but in another directory. So my question is: How do I rewrite the first regex to ignore folders or slashes? As I believe this is the root of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/ Share on other sites More sharing options...
ginerjm Posted January 17, 2014 Share Posted January 17, 2014 Sorry - don't know much about regex strings. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465620 Share on other sites More sharing options...
kicken Posted January 17, 2014 Share Posted January 17, 2014 Why not just swap the order of them so the second regex is tested first? Order all your rewrites from most-specific to least specific. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465621 Share on other sites More sharing options...
Lukeidiot Posted January 17, 2014 Author Share Posted January 17, 2014 Why not just swap the order of them so the second regex is tested first? Order all your rewrites from most-specific to least specific. Good idea, but I just tried this way and it doesn't seem to make a difference. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465622 Share on other sites More sharing options...
jazzman1 Posted January 17, 2014 Share Posted January 17, 2014 (edited) Where is the dolar sign in second example? Try, "^/?sc5/view/(.*)$" => "/sc5/view/index.php?i=$1" Edited January 17, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465623 Share on other sites More sharing options...
Lukeidiot Posted January 18, 2014 Author Share Posted January 18, 2014 (edited) Where is the dolar sign in second example? Try, "^/?sc5/view/(.*)$" => "/sc5/view/index.php?i=$1" I changed that but I dont think that is my problem. Its that everything in /sc5/ folder is being included into index.php, even the dirs (sc5/view/) Edited January 18, 2014 by Lukeidiot Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465626 Share on other sites More sharing options...
jazzman1 Posted January 18, 2014 Share Posted January 18, 2014 (edited) No. If you have a string for example: /sc5/view/jazzman the service's engine should be redirect it to /sc5/view/index.php?i=jazzman. That's all and pretty simple. PS: Does a sc5 directory is a subdirectory of root one or is a subdir of another directory in the server? Describe the server structure. Edited January 18, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465627 Share on other sites More sharing options...
Lukeidiot Posted January 18, 2014 Author Share Posted January 18, 2014 No. If you have a string for example: /sc5/view/jazzman the service's engine should be redirect it to /sc5/view/index.php?i=jazzman. That's all and pretty simple. PS: Does a sc5 directory is a subdirectory of root one or is a subdir of another directory in the server? Describe the server structure. /html/sc5 is the server directory (the main site is in /html/sc5 and the view is in /html/sc5/view) Your method DOES work, the only problem is that the first regex (or second, order doesnt matter it seems with lighttpd) overrides your regex. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465631 Share on other sites More sharing options...
sKunKbad Posted January 18, 2014 Share Posted January 18, 2014 What kind of router are you using? Are you using controllers? I guess I don't see why the rewrite rules are a good choice for doing what you are doing. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465641 Share on other sites More sharing options...
Lukeidiot Posted January 18, 2014 Author Share Posted January 18, 2014 What kind of router are you using? Are you using controllers? I guess I don't see why the rewrite rules are a good choice for doing what you are doing. Well that is half the problem -- I'm not very good with regex. My main goal is to rewrite example.com/index.php?go=test to example.com/test/, then rewrite example.com/view/index.php?i=100 to example.com/view/1 Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465643 Share on other sites More sharing options...
sKunKbad Posted January 18, 2014 Share Posted January 18, 2014 If you only have a couple of rewrites, you might try using mod_rewrite (and one of the thousands of tutorials found online). If you've never used one of the popular php frameworks, you might check one out, even if all you do is use it for routing. In fact, if all you need is a good routing solution, Slim is worth looking at. Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465645 Share on other sites More sharing options...
Lukeidiot Posted January 18, 2014 Author Share Posted January 18, 2014 If you only have a couple of rewrites, you might try using mod_rewrite (and one of the thousands of tutorials found online). If you've never used one of the popular php frameworks, you might check one out, even if all you do is use it for routing. In fact, if all you need is a good routing solution, Slim is worth looking at. I am using lighttpd which does not support mod_rewrite, nor .htaccess. That is why I have to apply the regex directly to my server config file (lighttpd.conf). Quote Link to comment https://forums.phpfreaks.com/topic/285460-conflicting-regex-to-clean-urls/#findComment-1465646 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.