0

I'm having some problems. I searched a lot, tried variations, and still can't get this working.

My aim is simply this:

Redirect: http://site.com/folder1/folder2/page

To: http://site.com/folder1/folder2/Page

Notice that I'm using "Friendly URLs".

Now here are the methods I tried, and the problems I came accross.

1) Redirect 301

Redirect 301 /folder1/folder2/page http://site.com/folder1/folder2/Page

This Redirect works, the problem is, my Get Variables from "page" are appearing at the end of the URL, which is bad for SEO:

http://site.com/folder1/folder2/Page?get=page

2) RewriteRule

RewriteRule of mod_rewrite is supposed to fix the problem of the Get Variables appearing (From what I've read).

The problem is, I'm not getting it to work for my Fancy URL structure.

RewriteRule ^/folder1/folder2/page$ http://site.com/folder1/folder2/Page [R=301,L]

It simply doesn't work. The Redirect isn't carried out, so something must be wrong here. I tried many variations to that code.

Can't you use RewriteRule directly on Friendly URLs?

(Friendly URL meaning I stripped off the .php extension)

Looking forward to some help! Thanks!


Update 1:

Please note that Case Sensitivity is Not the issue here.

Even if my example was: Page1 => Page 2

Instead of: page => Page

The problems still persist.


Update 2:

This is the closest solution I got so far (but still not there yet):

Redirect 301 /folder1/folder2/page http://site.com/folder1/folder2/Page?

I added a "?" at the end.

This will give me the landing URL of: http://site.com/folder1/folder2/Page?

It removes the Get Variables, but still not as SEO friendly as I would like.

2 Answers2

0

In the second case, if you are adding the rewrite rule in your htaccess file, the leading slash shouldn't be matched against.

Try:

RewriteRule ^folder1/folder2/page$ http://site.com/folder1/folder2/Page [R=301,L]

why you ask? Good question!

  • Hi, hanks for the suggestion! I tried this, but it didn't work unfortunately. :( It doesn't redirect. I tried many variations to RewriteRule, and I can't get any working with Friendly URLs. – Andrew Davis Nov 07 '12 at 18:38
0

I can't say I'm totally clear on the question here: are you trying to get the capitalization rule to match or to lose any query string? Both?

If it's capitalization, I believe the rule works (with the corrected typo Rajesh and hakre call out) removed. It it's the desire to strip the query string try adding a trailing ? to the second half of your rule. It'd look like:

RewriteRule ^folder1/folder2/page$ http://site.com/folder1/folder2/Page? [R=301,L]
David Hayes
  • 151
  • 5
  • Hi David, the problem isn't really about Capitalization. Even if I used **Page1 => Page2**, the redirect still isn't working. I tried your suggestion also, with adding "?" at the end of the 2nd URL. It still doesn't work. – Andrew Davis Nov 07 '12 at 19:00
  • Sorry, where are you putting your RewriteRule? I literally have that rule working perfectly for me (from a .htaccess file), so I'm thinking the issue is that your rule is just being ignored/not executed. You want to make sure you have `RewriteEngine on` before the rule. – David Hayes Nov 07 '12 at 19:07
  • My RewriteRule is at the end of my .htaccess file. I'm sure that it's being executed, because if I try other forms (Not Friendly-URL) they are redirecting. But I need Friendly-URL for this case. Yes I do also have `RewriteEngine on`. – Andrew Davis Nov 07 '12 at 19:13
  • Sorry, I'm not familiar with this "Redirect 301 ..." syntax your update above uses. Not sure I can be of help. That syntax doesn't work for me in a .htaccess file either, so I'm a bit confused. Is there a reason not to use the working RewriteRule? – David Hayes Nov 07 '12 at 19:26
  • It's no problem David. Thanks very much for trying to help. Yes it's odd that the "Redirect 301" isn't working for you. It can be found on many Online Tutorials. Possibly it only works on Linux Apache or a few environments. See here: http://www.velvetblues.com/web-development-blog/301-redirects-with-htaccess-files-on-linux-apache/ – Andrew Davis Nov 07 '12 at 19:36
  • But really, is there a reason you're using that older syntax and not the RewriteRule that I've verified as working? (I've got Apache on a Linux box, etc. What's true is that my RewriteRule above works and your "Redirect 301..." rule doesn't, so I don't understand why you're not just using my RewriteRule that works.) – David Hayes Nov 07 '12 at 19:43
  • I tried using your RewriteRule method, and it simply isn't working for me. :/ I don't have a reason to use the Older syntax, I just want something that works well. – Andrew Davis Nov 07 '12 at 19:54