Johns3n Posted December 22, 2012 Share Posted December 22, 2012 (edited) Hello PHPFreaks Been a long time since i've been here last time! (hopefully it means that i'm getting better However! I'm playing around with "new" technology the mod_rewrite for the .htaccess file. I'm writting a php app where the url has 2 parameters. example.com?path=this/is/a/path/to/this/&slug=page NOW my dilemma is that my .htaccess rules work IF there is NO / (slash) in the ?path= var (since I separate the 2 vars at a /). my question is now! (bear in mind here that i'm a ROOKIE at .htaccess rewriting) how do i go about in the .htaccess file to make it reconize that whatever comes after the last slash the $2 variable and everything is $1 - even if there is no $path defined in the url? BTW! I'm not looking for free handouts and do my coding here! I'm willing to learn here but just need pointers!! I've pasted my .htaccess file here: Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_URI} !=/index.php RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)$ /index.php?slug=$1&type=$2&view=$3&action=$4 [L,PT] RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)$ /index.php?slug=$1&type=$2&view=$3 [L,PT] RewriteRule ^([^/.]+)/([^/.]+)$ /index.php?path=$1&slug=$2 [L,PT] RewriteRule ^([^/.]+)$ /index.php?slug=$1 [L,PT] RewriteRule ^(.+)/$ /$1 [R=301,L] Thanks in advance Edited December 22, 2012 by Johns3n Quote Link to comment https://forums.phpfreaks.com/topic/272297-how-to-handle-xx-amount-of-slashes-in-a-rewritten-url/ Share on other sites More sharing options...
requinix Posted December 22, 2012 Share Posted December 22, 2012 So example.com?path=this/is/a/path/to/this/&slug=page is the destination URL, and that's supposed to be the result of going to example.com/this/is/a/path/to/this/page Right? Quote Link to comment https://forums.phpfreaks.com/topic/272297-how-to-handle-xx-amount-of-slashes-in-a-rewritten-url/#findComment-1400941 Share on other sites More sharing options...
Johns3n Posted December 23, 2012 Author Share Posted December 23, 2012 Indeed!! But it could also just be: example.com/a/path/this/is/page or even example.com/path/to/page Quote Link to comment https://forums.phpfreaks.com/topic/272297-how-to-handle-xx-amount-of-slashes-in-a-rewritten-url/#findComment-1400989 Share on other sites More sharing options...
Johns3n Posted December 23, 2012 Author Share Posted December 23, 2012 It could also even just be: example.com/page So it just uses the ?slug=page variable and the first ?path=something variable is just defined as: if(!isset($_GET['path'])){ $_GET['path'] = NULL; } in the PHP app. Quote Link to comment https://forums.phpfreaks.com/topic/272297-how-to-handle-xx-amount-of-slashes-in-a-rewritten-url/#findComment-1400993 Share on other sites More sharing options...
requinix Posted December 23, 2012 Share Posted December 23, 2012 But /path/to/page will also match your RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)$ /index.php?slug=$1&type=$2&view=$3 [L,PT] It's ambiguous. Quote Link to comment https://forums.phpfreaks.com/topic/272297-how-to-handle-xx-amount-of-slashes-in-a-rewritten-url/#findComment-1401050 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.