BenWeston Posted March 10, 2014 Share Posted March 10, 2014 Hi all I'm trying to get my .htaccess file to internally redirect from, say: mysite.com/salon/the-name-of-someone/treatments to... mysite.com/salon/treatments.php?salon=the-name-of-someone I'm trying the following, but it won't work: RewriteRule salon/([a-z0-9\-]+)/treatments$ /salon-stub/index.php?salon=$1 [L] I think the following rule which redirects mysite.com/salon/the-name-of-someone to mysite.com/salon/index.php?salon=the-name-of-someone (successfully), might be causing the problem: RewriteRule salon/([a-z0-9\-]+)$ /salon-stub/index.php?salon=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/286854-rewrite-rule-doesnt-work/ Share on other sites More sharing options...
requinix Posted March 10, 2014 Share Posted March 10, 2014 Did you notice that both of those RewriteRules are trying to redirect to the same place? I thought you wanted the first to go to treatments.php and not index.php... Quote Link to comment https://forums.phpfreaks.com/topic/286854-rewrite-rule-doesnt-work/#findComment-1472047 Share on other sites More sharing options...
BenWeston Posted March 10, 2014 Author Share Posted March 10, 2014 (edited) Sorry, I mistyped the first one, it should be: RewriteRule salon/([a-z0-9\-]+)/treatments$ /salon-stub/treatments.php?salon=$1 [L] (which doesn't work) Edited March 10, 2014 by BenWeston Quote Link to comment https://forums.phpfreaks.com/topic/286854-rewrite-rule-doesnt-work/#findComment-1472057 Share on other sites More sharing options...
requinix Posted March 10, 2014 Share Posted March 10, 2014 Looks right so far. Can you post your entire .htaccess as-is? Maybe there's a conflict between rules. And when you say "doesn't work", what does that mean? What actually happens? Quote Link to comment https://forums.phpfreaks.com/topic/286854-rewrite-rule-doesnt-work/#findComment-1472069 Share on other sites More sharing options...
BenWeston Posted March 10, 2014 Author Share Posted March 10, 2014 (edited) Thanks for the help so far, requinix! Here's the complete .htaccess: RewriteEngine On # If it's not a directory... RewriteCond %{REQUEST_FILENAME} !-d # ...and it has a trailing slash then redirect to URL without slash RewriteRule ^(.+)/$ /$1 [L,R=301] # Rewrite rules for profiles and username mapping RewriteRule ^([a-z0-9\-]+)$ /user/index.php?prof=$1 [L] RewriteRule ^([a-z0-9\-]+)/treatments$ /user/treatments.php?prof=$1 [L] RewriteRule ^([a-z0-9\-]+)/reviews$ /user/reviews.php?prof=$1 [L] RewriteRule ^([a-z0-9\-]+)/photos$ /user/photos.php?prof=$1 [L] # Rewrite rules for salons RewriteRule salon/([a-z0-9\-]+)$ /salon-stub/index.php?salon=$1 [L] RewriteRule salon/([a-z0-9\-]+)/treatments$ /salon-stub/treatments.php?salon=$1 [L] The last two lines are the ones I'm concerned with but I understand something else may be causing these to be ineffective. Essentially, I want exactly the same redirection for 'salons' as I have for 'profiles and username mapping' (that already works), except the salons are under the /salons/ directory, and usernames and profiles are under root. Edited March 10, 2014 by BenWeston Quote Link to comment https://forums.phpfreaks.com/topic/286854-rewrite-rule-doesnt-work/#findComment-1472078 Share on other sites More sharing options...
requinix Posted March 10, 2014 Share Posted March 10, 2014 And what did you say happens when you try to go to the URL that isn't working? Also, try adding an [R] to all of those rules to make the redirect happen externally - so you can see where you're being redirected. Quote Link to comment https://forums.phpfreaks.com/topic/286854-rewrite-rule-doesnt-work/#findComment-1472082 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.