Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2012, 10:49 PM   PM User | #1
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
htaccess 301 redirect not working

Hi guys i know this is not php but i cant see where this should go on this forum.

I also know that you guys know htaccess as i see you guys using it some times.

I know a little bit of it and normally i do not need help with htaccess but i cant seem to get the 301 redirect to work.

I am wanting to change an ugly old file which is:

blog-article.php?id=14

to

blog-post/logo-in-5-minutes-photoshop-tutorial/1/

And so on for a few of them.

The redirect is so that the pr rank goes to its new url as these are pr3-4 so do not want to lose these ranks.

Here is the code, could you please tell me what i am doing wrong.

Code:
RewriteRule ^blog-article.php?id=14 http://www.domain.co.uk/blog-post/logo-in-5-minutes-photoshop-tutorial/1/ [R=301,L]
Thanks
devinmaking is offline   Reply With Quote
Old 01-03-2012, 11:09 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 46
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by devinmaking View Post
Hi guys i know this is not php but i cant see where this should go on this forum.
Erm.. how about here: Apache configuration

How you missed that is beyond me
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Old 01-03-2012, 11:15 PM   PM User | #3
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Thanks,

I dont know why i could not see that lol.

Do i start a new thread or weight for mod to move it?
devinmaking is offline   Reply With Quote
Old 01-03-2012, 11:26 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,751
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yep, moving to apache configurations.

This is backwards. Unless you have a specific index file to work with? Typically its the other way around, you would map a more textual representation to that of using the id's or names. I don't recommend going the other way around.
The url will show what the user types in. You cannot force that to change, only where it goes. So if they type in ?id=14, that is where they go and what they will see. You can write a replacer in PHP to have it provide the links in an expanded format, but I wouldn't recommend hard coding that since that now requires that mod_rewrite be in use. Declare an environment variable in the <IfModule mod_rewrite.c> block, and alter the links as desired in PHP.
Fou-Lu is offline   Reply With Quote
Old 01-03-2012, 11:30 PM   PM User | #5
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by Fou-Lu View Post
Yep, moving to apache configurations.

This is backwards. Unless you have a specific index file to work with? Typically its the other way around, you would map a more textual representation to that of using the id's or names. I don't recommend going the other way around.
The url will show what the user types in. You cannot force that to change, only where it goes. So if they type in ?id=14, that is where they go and what they will see. You can write a replacer in PHP to have it provide the links in an expanded format, but I wouldn't recommend hard coding that since that now requires that mod_rewrite be in use. Declare an environment variable in the <IfModule mod_rewrite.c> block, and alter the links as desired in PHP.
Ive done all the php work

This is for search engines and other sites that are linking to www.domain.co.uk/blog-article.php?id=14 to redirect to its new page which is search engine friendly.
devinmaking is offline   Reply With Quote
Old 01-04-2012, 08:18 AM   PM User | #6
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
I agree, this is back to front. Typically you'd have a link like:

http://www.mydomain.null/logo-in-5-m...op-tutorial/1/

and mod_rewrite would match that, and internally redirect it to:

www.domain.co.uk/blog-article.php?id=14

You probably could make your rule to do it the other way around, but I don't see much point if you are trying to tidy things up and make them clearer, as you are actually munging things and making them less clear.

It's also worth mentioning that if the search engine is already listing:

www.domain.co.uk/blog-article.php?id=14

in its index, then I'd say the URL was pretty much 'search engine friendly' already :-)
leslie.jones is offline   Reply With Quote
Old 01-04-2012, 08:52 AM   PM User | #7
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
Just adding to that, if you *really* want to do it (and for the sake of Google bringing people here):

The reason your version fails is because of the ? question mark ? You cannot use the question mark in the match as it signals a querystrings which is caught as separate data.

This basic example will do what you want for the specific URL quoted, but it can probably be better refined or optimised.
Code:
RewriteCond %{REQUEST_URI} ^/blog-article.php$
RewriteCond %{QUERY_STRING} ^id=14$ 
RewriteRule ^(.*)$ http://www.google.co.uk [R=301,L]
Hope that helps.
leslie.jones is offline   Reply With Quote
Old 01-04-2012, 11:02 PM   PM User | #8
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by leslie.jones View Post
Just adding to that, if you *really* want to do it (and for the sake of Google bringing people here):

The reason your version fails is because of the ? question mark ? You cannot use the question mark in the match as it signals a querystrings which is caught as separate data.

This basic example will do what you want for the specific URL quoted, but it can probably be better refined or optimised.
Code:
RewriteCond %{REQUEST_URI} ^/blog-article.php$
RewriteCond %{QUERY_STRING} ^id=14$ 
RewriteRule ^(.*)$ http://www.google.co.uk [R=301,L]
Hope that helps.
I was told by someone from seomoz that to keep the pr4 rank for that page plus to keep google happy by the links still going to the relevant pages to 301 direct the old url to the new one.

Can someone please tell me why this is backwards?

Its only applying to what google are asking for is it not?

Thanks
devinmaking is offline   Reply With Quote
Old 01-05-2012, 07:57 AM   PM User | #9
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
I'm no expert on Google metrics - so I'm not qualified to answer, but in a logical context I would look at it like this:

LINK GOES DIRECTLY TO RELEVANT CONTENT WITHOUT INTERVENTION
LINK = GOOD, KEEP IN INDEX

LINK GOES INDIRECTLY TO RELEVANT CONTENT VIA A REDIRECT
LINK = RUBBISH, NOT POINTING TO RIGHT PLACE, DROP/MODIFY

Effectively, and I stress as a LOGICAL problem, I don't want a link to something being redirected - I want to go direct to the resource, and I would penalise for a redirect (which means not only the link is effectively pointing to the wrong resource, but also resulting in more traffic to achieve the required result).

To square that, a redirect is probably useful if you move a page and want it re-indexed. However there will probably come a point where if you redirect the same resource for two long there may be a pay-off or penalisation metric.

I must stress, however, I know very little about SEO, I know about Apache. As far as SEO is concerned I've always been lucky enough to get sites listed and well placed in search engines by using clean, relevant content with properly formatted pages and targeting specific demographics for the business concerned, but I know others who have more general sites in swamped sectors have an uphill battle.
leslie.jones is offline   Reply With Quote
Old 01-05-2012, 08:19 AM   PM User | #10
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by leslie.jones View Post
I'm no expert on Google metrics - so I'm not qualified to answer, but in a logical context I would look at it like this:

LINK GOES DIRECTLY TO RELEVANT CONTENT WITHOUT INTERVENTION
LINK = GOOD, KEEP IN INDEX

LINK GOES INDIRECTLY TO RELEVANT CONTENT VIA A REDIRECT
LINK = RUBBISH, NOT POINTING TO RIGHT PLACE, DROP/MODIFY

Effectively, and I stress as a LOGICAL problem, I don't want a link to something being redirected - I want to go direct to the resource, and I would penalise for a redirect (which means not only the link is effectively pointing to the wrong resource, but also resulting in more traffic to achieve the required result).

To square that, a redirect is probably useful if you move a page and want it re-indexed. However there will probably come a point where if you redirect the same resource for two long there may be a pay-off or penalisation metric.

I must stress, however, I know very little about SEO, I know about Apache. As far as SEO is concerned I've always been lucky enough to get sites listed and well placed in search engines by using clean, relevant content with properly formatted pages and targeting specific demographics for the business concerned, but I know others who have more general sites in swamped sectors have an uphill battle.
As the page of blog-article?id=14 was moved to a seo friendly url is that not a reason for a redirect?

If i dont redirect then google will take away the pr4 next time round, i am confused now lol...
devinmaking is offline   Reply With Quote
Old 01-05-2012, 09:22 AM   PM User | #11
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by leslie.jones View Post
Just adding to that, if you *really* want to do it (and for the sake of Google bringing people here):

The reason your version fails is because of the ? question mark ? You cannot use the question mark in the match as it signals a querystrings which is caught as separate data.

This basic example will do what you want for the specific URL quoted, but it can probably be better refined or optimised.
Code:
RewriteCond %{REQUEST_URI} ^/blog-article.php$
RewriteCond %{QUERY_STRING} ^id=14$ 
RewriteRule ^(.*)$ http://www.google.co.uk [R=301,L]
Hope that helps.
The only problem with this is you can only use this once.

i have 8 urls.

id=6 etc once, you have queried the blog once it does not allow you to do the same for others.
devinmaking is offline   Reply With Quote
Old 01-05-2012, 01:32 PM   PM User | #12
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
Normally (which is a bit of a generalisation as there is no such thing tbh).....

You would have some clear and defined structure, and be working the other way round, that is:

Code:
LINK: mysite.com/tutorials/1 --->REDIRECT ---> mysite.com/show.php?id=1
LINK: mysite.com/tutorials/2 --->REDIRECT ---> mysite.com/show.php?id=2
LINK: mysite.com/tutorials/3 --->REDIRECT --->mysite.com/show.php?id=3
With this, your rewrite code can grab the '/1, /2, /3' and use that data in the redirect response - so you would have one rule to deal with all cases, plus a safety trap that redirects any non-existent files/pages should some user request something like mysite.com/tutorials/9999999999.

But you are working back to front because you are trying to transcribe:
Code:
LINK: blog-article.php?id=14 --->REDIRECT ---> /blog-post/logo-in-5-minutes-photoshop-tutorial/1/
From a code perspective there is no structure for mod_rewrite to work with, and you have no choice but to use an individual rule for id=14 for it to redirect to: /blog-post/logo-in-5-minutes-photoshop-tutorial/1/. If you only have 8 links it is not the end of the world, just write 8 rules. It's not optimal, but it should work without obvious issue.

MOD_REWRITE is not always the answer. Sometimes it is better to have a scripted handler that grabs the querystring, looks it up in a local array, table or database, and redirects based upon that. In your case, where your links are already making use of a querystring it may be a better option to put a simple php redirector together.

As for page ranking et al, it is not an area I can honestly say I am confident to give good advice in. I think in terms of logic, mostly, but this may be flawed and not match the metric used by search engines.

Quote:
id=6 etc once, you have queried the blog once it does not allow you to do the same for others.
Once you arrive at the target page (by redirection or directly) your links on that page should be fixed to point directly to the correct place and need no redirection, surely?

Last edited by leslie.jones; 01-05-2012 at 01:34 PM..
leslie.jones is offline   Reply With Quote
Old 01-05-2012, 01:52 PM   PM User | #13
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by leslie.jones View Post
Normally (which is a bit of a generalisation as there is no such thing tbh).....

You would have some clear and defined structure, and be working the other way round, that is:

Code:
LINK: mysite.com/tutorials/1 --->REDIRECT ---> mysite.com/show.php?id=1
LINK: mysite.com/tutorials/2 --->REDIRECT ---> mysite.com/show.php?id=2
LINK: mysite.com/tutorials/3 --->REDIRECT --->mysite.com/show.php?id=3
With this, your rewrite code can grab the '/1, /2, /3' and use that data in the redirect response - so you would have one rule to deal with all cases, plus a safety trap that redirects any non-existent files/pages should some user request something like mysite.com/tutorials/9999999999.

But you are working back to front because you are trying to transcribe:
Code:
LINK: blog-article.php?id=14 --->REDIRECT ---> /blog-post/logo-in-5-minutes-photoshop-tutorial/1/
From a code perspective there is no structure for mod_rewrite to work with, and you have no choice but to use an individual rule for id=14 for it to redirect to: /blog-post/logo-in-5-minutes-photoshop-tutorial/1/. If you only have 8 links it is not the end of the world, just write 8 rules. It's not optimal, but it should work without obvious issue.

MOD_REWRITE is not always the answer. Sometimes it is better to have a scripted handler that grabs the querystring, looks it up in a local array, table or database, and redirects based upon that. In your case, where your links are already making use of a querystring it may be a better option to put a simple php redirector together.

As for page ranking et al, it is not an area I can honestly say I am confident to give good advice in. I think in terms of logic, mostly, but this may be flawed and not match the metric used by search engines.


Once you arrive at the target page (by redirection or directly) your links on that page should be fixed to point directly to the correct place and need no redirection, surely?
I had an old website that was really outdated.

There was no seo within the pages, the urls were all variables etc and not pretty.

So i completely re built the website.

Now the website has a different structure and completely different urls.

For instance my old contact page was say-hello.php

The new one is now, /contact-us/

The reason for the 301 is so that all old pages point to the same content which has now moved in url.

Ive spoken to people on seoforum.ord and seomoz.com and they have all stated that a 301 is a must if i want to keep page authority and rank for each and every page, plus all links from external websites still point to a relevent page.

That is why this is needed.

The query code which was given above made it so it added the id=14 on the end of the redirect which is causing a problem, which means the query can only be input once because on the next one it shows a page 404 instead.

Thanks
devinmaking is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:14 PM.


Advertisement
Log in to turn off these ads.