PDA

View Full Version : Broken links - HELP!



Hitman
10-07-2010, 10:13 AM
Hi guys,

I have created a site in PHP that allows me to have URLs like http://site.com/this-is-a-page

I've done it with custom 404 pages... basically it gets whats at the end of the URL, checks for it in the database and if it's there it'll display the content for that specific url. I find it looks better than view.php?id=1 and is more informative if somebody sees the link.

Problem is Google hadn't indexed these links! I was confused why, so I did some looking around and created a sitemap - all of the custom URLs could not be added because they were 'broken links' - how do I get around this? Wordpress does it and other sites, what do I need to do?

Thanks.

Fehm
10-07-2010, 11:00 AM
Look into .htaccess and maybe mod_rewrite but I'm unsure sorry :L

Hitman
10-07-2010, 11:12 AM
OK got some info on that.


RewriteEngine On
RewriteRule ^(.*).html view.php?url=$1

That will direct page-name.html to view.php?url=page-name (which then executes a query to get the info and displays) - I don't want .html on the end, so I change it to this...


RewriteEngine On
RewriteRule ^(.*) view.php?url=$1

That now gives nothing - every page on the website is BLANK. So it would be site.com/page-name but it's blank... However if I do this...



RewriteEngine On
RewriteRule ^(.*)/ view.php?url=$1

site.com/page-name comes up with 404, HOWEVER site.com/page-name/ comes up with the thing I want... but I don't want the trailing slash as when it's not added it won't work.

HELP!

Apolva
10-07-2010, 12:37 PM
Google won't index pages with a 404 response.



RewriteEngine On
RewriteRule ^(.*) view.php?url=$1
The reason that shows a blank page is because it creates an infinite loop - the final URL matches the target URL and so on. Try changing to:



RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) view.php?url=$1


This checks and only redirects if the file doesn't exist (avoiding an infinite redirect).

Hitman
10-07-2010, 12:53 PM
Google won't index pages with a 404 response.



RewriteEngine On
RewriteRule ^(.*) view.php?url=$1
The reason that shows a blank page is because it creates an infinite loop - the final URL matches the target URL and so on. Try changing to:



RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) view.php?url=$1


This checks and only redirects if the file doesn't exist (avoiding an infinite redirect).I love you again. That has worked. I was working on a redirect when page-name is there to page-name/ 'cos it worked with a slash, but I don't want the slash... and what you've done works without it. You are awesome.

Want to hide these adverts? Register an account for free!