HaLo2FrEeEk Posted January 3, 2008 Share Posted January 3, 2008 I need help with a .htaccess modRewrite command. I'm trying to convert this url: http://claninfectionist.com/tutorials/?cat=photoshop&tut=pipe To this: http://claninfectionist.com/tutorials/photoshop/pipe To help with SEO. The thing is...well, a couple things, the tutorials section was set up after my site and I already had a few up, I was using a file based system before I went to database so my images in my tutorials are ../imagename.png, not actual filepaths. I use the cat and tut values to replace all ../'s with [category]/[tutorial]/imagename.png, so that needs to be preserved, it would be too much work to fix all the tutorials. This is the RewriteRule I tried, it didn't seem to work: rewriterule ^([^-]+)/([^&]+)$ index\.php?cat=$1&tut=$2 I also need it to rewrite when the user is viewing just the category: http://claninfectionist.com/tutorials/?cat=photoshop to http://claninfectionist.com/tutorials/photoshop Or if index.php is included in the url: http://claninfectionist.com/tutorials/index.php?cat=photoshop&tut=pipe to http://claninfectionist.com/tutorials/photoshop/pipe And still maintain that system of replacing the ../'s. Any help would be very nice. TYIA! Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted January 5, 2008 Author Share Posted January 5, 2008 Bump. I know this forum doesn't get too much activity, but I know there are people who can help me, please. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted January 6, 2008 Author Share Posted January 6, 2008 Bump, PLEASE! Quote Link to comment Share on other sites More sharing options...
madmax Posted January 8, 2008 Share Posted January 8, 2008 Not sure if you have found a solution yet. Looks like you may after checking your site. Your requirements are a little bit more flexible than first appears. I managed to simulate this on my local machine using localhost.com but not using .htaccess files. If you use .htaccess files remember to add a RewriteBase statement The "empty case" for the index file (/tutorials/?) complicates rewrites since an extra otherwise / has to be added Also, since the rewritten local file isn't "passed thru" to the mod alias etc. the user "sees" the original URL (/tutorial) even though the correct file is retrieved. Also, because of this you need to always "force" the correct index filename (index.php coded as default). Generally I'd have thought this would be better done using a redirection (code 30x) - particularly since you're using PHP - PHP might have been a better bet for generating redirection. Try this... RewriteEngine On RewriteCond %{QUERY_STRING} ^cat=(.*)&tut=(.*)$ [NC] RewriteRule ^/tutorials/$ /tutorials/%1/%2/index.php? [NC,L] RewriteCond %{QUERY_STRING} ^cat=(.*)&tut=(.*)$ [NC] RewriteRule ^/tutorials/(.*) /tutorials/%1/%2/$1? [NC,L] RewriteCond %{QUERY_STRING} ^cat=(.*)$ [NC] RewriteRule ^/tutorials/$ /tutorials/%1/index.php? [NC,L] RewriteCond %{QUERY_STRING} ^cat=(.*)$ [NC] RewriteRule ^/tutorials/(.*) /tutorials/%1/$1? [NC,L] Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted January 13, 2008 Author Share Posted January 13, 2008 I tried your code and it didn't work. If I go to: http://claninfectionist.com/tutorials/?cat=photoshop&tut=pipe The page shows up just fine, but when I go to: http://claninfectionist.com/tutorials/photoshop/pipe Like I want it to be displayed, it gives me my 403 access forbidden error page. I basically just want to get rid of the dynamic url's and go with the standard folder heirarchy. I know it can be done with htaccess as I've done it with other things, but those only had one url variable, this has the potential for 2. Quote Link to comment Share on other sites More sharing options...
madmax Posted January 13, 2008 Share Posted January 13, 2008 Check your logs to see what actual URL is being resolved and triggering the 403 error (check both error and access logs) It might help to post the line from each log (error/access) re: this 403 error Rule out access rights issues at this stage before moving back to look at the rewrite rule (because it's quick and easy to do it at this stage ) If the path being denied is not what you expected go back to the rule and enable rewrite logging to check if the rule is resolving to the correct physical path. If the path really is being rewritten to what you expected then check access rights and content 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.