bigheadedd Posted May 6, 2010 Share Posted May 6, 2010 Hi, I've been having problems with my seo friendly links. I was wondering if anyone could help at all? Options +FollowSymLinks RewriteEngine On RewriteRule photos/([a-zA-z]+)\.html$ photos.php?view=$1 RewriteRule artwork/([a-zA-z]+)\.html$ artwork.php?view=$1 RewriteRule ([a-zA-z]+)\.html$ index.php?page=$1 RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2 RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2&pid=$3 RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2 RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3 The top five lines are fine, its the bottom four which are causing me problems.. Whichever two lines (artwork or photos) are last are the ones that work. I know I can put a ^ at the beginning, but this doesn't seem to work. Any help would be hugely helpful! Many thanks E Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/ Share on other sites More sharing options...
JonnoTheDev Posted May 6, 2010 Share Posted May 6, 2010 You have the same rewrite rules for different files! Prefix them with something to make them different. RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2 RewriteRule ([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2 i.e. RewriteRule ^artwork/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2 RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2 Change the urls so they match the rules. Also dont start a rewrite using ([a-zA-z0-9]+) As it allows any alphanumeric text it clashes with your other rules. Again, prefix with a string of meaning as above. Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054145 Share on other sites More sharing options...
bigheadedd Posted May 6, 2010 Author Share Posted May 6, 2010 Thats still not working unfortunately! It just makes it come up with 404 not found? Any ideas? On its own it should be like this: ie: photos.php?name=text&cid=1&pid=1 artwork.php?name=text&cid=1&pid=1 and the same but without the pid at the end. I'm a bit stuck! Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054180 Share on other sites More sharing options...
cags Posted May 6, 2010 Share Posted May 6, 2010 404 normally results because the RewriteBase isn't set, try adding RewriteBase / Just below RewriteEngine On. Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054190 Share on other sites More sharing options...
bigheadedd Posted May 7, 2010 Author Share Posted May 7, 2010 Unfortunately thats not working either! When I add RewriteBase / it still 404's, and causes all of the top three clauses to 404 too! Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054464 Share on other sites More sharing options...
JonnoTheDev Posted May 7, 2010 Share Posted May 7, 2010 You have added an extra paramater on the end, that is why! (pid) Here is the correct rule RewriteRule ^photos/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3 photos.php?name=text&cid=1&pid=1 Will become http://www.domain.com/photos/text/1/1.html Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054486 Share on other sites More sharing options...
bigheadedd Posted May 7, 2010 Author Share Posted May 7, 2010 Its still not working? Am I missing something? Here is my complete .htaccess file: Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule photos/([a-zA-z]+)\.html$ photos.php?view=$1 RewriteRule artwork/([a-zA-z]+)\.html$ artwork.php?view=$1 RewriteRule ([a-zA-z]+)\.html$ index.php?page=$1 RewriteRule ^artwork([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2 RewriteRule ^artwork/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)\.html$ artwork.php?name=$1&cid=$2&pid=$3 RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2 RewriteRule ^photos/([a-zA-Z0-9]+)/([0-9]+)/([0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3 Any help would be amazing! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054493 Share on other sites More sharing options...
cags Posted May 7, 2010 Share Posted May 7, 2010 What is the URL that you are typing into the browser/clicking on? What is the URL you wish to end up in the address bar for this example? Where is that file actually located on your server? Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054497 Share on other sites More sharing options...
bigheadedd Posted May 7, 2010 Author Share Posted May 7, 2010 The url i'm typing is: http://localhost:8888/website/photos/personal/6.html The actual hard link is: http://localhost:8888/website/photos.php?name=personal&cid=6 I have two sections: Artwork & photos They do the same job just with different content, however they are just separated by the files. all of the files: artwork.php photos.php index.php are located just in the /website folder where the .htaccess is. It works with just 'photos' or just 'artwork' but not together. Thanks, E Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054501 Share on other sites More sharing options...
cags Posted May 7, 2010 Share Posted May 7, 2010 Ok, given that information I believe your RewriteBase should actually be... RewriteBase /website/ One technique I always use for testing is to add the [R=302] flag to the end of a rule I'm testing, this will actually redirect the browser so you will see in the address bar what URL Apache is serving, this normally gives a good indication what went wrong. Once you get the right page you can remove the flag. Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054514 Share on other sites More sharing options...
bigheadedd Posted May 7, 2010 Author Share Posted May 7, 2010 I think that last line helped, however its still not working. Does the [R=302] tag mean that it should show the hard link? Options +FollowSymLinks RewriteEngine On RewriteBase /website/ RewriteRule ^photos/([a-zA-z]+)\.html$ photos.php?view=$1 [R=302] RewriteRule ^artwork/([a-zA-z]+)\.html$ artwork.php?view=$1 [R=302] RewriteRule ^([a-zA-z]+)\.html$ index.php?page=$1 [R=302] RewriteRule ^artwork/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2 [R=302] RewriteRule ^artwork/([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ artwork.php?name=$1&cid=$2&pid=$3 [R=302] RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2 [R=302] RewriteRule ^photos/([a-zA-z0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)\.html$ photos.php?name=$1&cid=$2&pid=$3 [R=302] It comes up with 404 on both photos & artwork. If I remove the ^photos/ or ^artwork/ then it will work for that page, but if I remove both, it will only work on the one that is on the last line (Hope that makes sense!) Any other ideas? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054524 Share on other sites More sharing options...
cags Posted May 7, 2010 Share Posted May 7, 2010 R=302 is a temporary redirect so yes, whatever is in the browser address bar is the page apache is trying to serve up, so yes, the 'hard link' as you put it. I've just realised all your patterns is a-zA-z, this is likely causing problems (notice the lower case z). Fixing that could easily make a big difference to behaviour. Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054543 Share on other sites More sharing options...
bigheadedd Posted May 7, 2010 Author Share Posted May 7, 2010 Finally! Thankyou for your help. I managed to figure out the problem. I realized that it was down to my seo links including '-' inbetween words. Obviously this wasn't including them, so was 404ing. I changed it to ([a-zA-Z0-9^-]+) and it works brilliantly! Thankyou all who helped! Quote Link to comment https://forums.phpfreaks.com/topic/200900-htaccess-seo-links/#findComment-1054554 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.