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.

Link to comment
Share on other sites

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(); }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.