Jump to content

What should I do with my old URL's after rewriting


Prodigal Son

Recommended Posts

Ok, so I've made my urls are nice. Instead of having:

www.mysite.com/index.php?pg=category&sect=sports&title=the-winner

I have:

www.mysite.com/sports/the-winner

 

This is the mod rewrite I used:

RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/?$ /index.php?pg=category&sect=$1&title=$2 [L]

 

That works nicely, but if you type in the url as www.mysite.com/index.php?pg=category&sect=sports&title=the-winner, that will also work. What do people usually do if you type that in? Do they just redirect them to a 404 page or index page? How would I go about doing that. It seems I can't just swap the above code around :D.

 

My next question is originally my page works by including files from GET. So if you type in www.mysite.com/includes/startpage.php, you will be able to see that page. What would be the best measure to take on that, just redirect the whole folder to a 404 page? Or index page maybe if there is a difference.

 

Thanks.

mod-rewrite actually rewrite the urls from...

www.mysite.com/sports/the-winner

to

www.mysite.com/index.php?pg=category&sect=sports&title=the-winner

 

so denying access to the later will render your site unusable. Just leave them.

 

If you don't want your includes accessed directly one of the easiest approuches is to simply set a constant within your index.php page. eg;

 

define('IS_INDEX',true);

 

then, within each include file simply check for its existence.

 

if (!isset(IS_INDEX)) { die(); }

 

mod-rewrite actually rewrite the urls from...

www.mysite.com/sports/the-winner

to

www.mysite.com/index.php?pg=category&sect=sports&title=the-winner

 

so denying access to the later will render your site unusable. Just leave them.

Oh I see. But if I leave those URLs up, even if I don't use those links anywhere will search engines still find them?

 

 

If you don't want your includes accessed directly one of the easiest approuches is to simply set a constant within your index.php page. eg;

 

define('IS_INDEX',true);

 

then, within each include file simply check for its existence.

 

if (!isset(IS_INDEX)) { die(); }

I get a weird error when I tried that:

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM

 

But no matter how much I change that around I still get the error, weird.

Is it just me or you can't use isset with a constant? I tried instead to check if IS_INDEX != true, then die/exit, but it doesn't seem to work, I can still see the include.

 

So I am trying to just redirect the whole directory. I'm using this:

Redirect /includes /index.php

 

But it will do something weird. Say my request is mysite.com/includes/header.php, it would bring me to the index page, but it will also add the file name to the end of the path in the address bar. So it would look like this now: mysite.com/includes/index.php/header.php

 

Anyone know how I would fix this? Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.