Forum Moderators: phranque

Message Too Old, No Replies

redirect from an URL with a + to the same URL with a -

         

spaceman813

1:18 pm on Jul 13, 2012 (gmt 0)

10+ Year Member



Hello everyone,
I have a problem with my website's URLs.
This website used to run on Gallery 2 CMS and the URLs were like

http://www.example.com/celebrities/v/models/male/name+surname/ (with a PLUS sign)

Now I moved it all to a new host and used Gallery 3 and the URLs now are

http://www.example.com/celebrities/v/models/male/name-surname/ (MINUS sign)

I tried this code (and lots of others) in the .htaccess file to redirect the old URL to the new one but when all I get is a 404 error when I try entering with a link with a PLUS sign in it, or else they stop the site from working altogether.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /celebrities/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
RewriteRule ^([^\+]*)\+([^\+]*)\+([^\+]*)\+([^\+]*)\+([^\+]*)$ $1-$2-$3-$4-$5 [L,R=301]
RewriteRule ^([^\+]*)\+([^\+]*)\+([^\+]*)\+([^\+]*)$ $1-$2-$3-$4 [L,R=301]
RewriteRule ^([^\+]*)\+([^\+]*)\+([^\+]*)$ $1-$2-$3 [L,R=301]
RewriteRule ^([^\+]*)\+([^\+]*)$ $1-$2 [L,R=301]
</IfModule>


PLease note that some urls have more than one "+" so I had to do that.

Also note that I'm a complete newbie on this, so it's really been one day of shots in the dark for me (I tried all sorts of codes I could find online and tried tweaking them to my needs).
What am I doing wrong?

g1smd

1:45 pm on Jul 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Second rule: $1 will always be empty.

Second and later rules which rewrite never get to run because (.*) in first rule matched all requests.

Redirects should be at start of file and rule target should include protocol and domain.

spaceman813

3:34 pm on Jul 13, 2012 (gmt 0)

10+ Year Member



thanks a lot for your reply but I have no idea what you said! Sorry!
I'd really appreciate if you could tell me what I should do practically. As I said I know nothing about all this

wilderness

4:09 pm on Jul 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Second rule: $1 will always be empty.


RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L] 


Second and later rules which rewrite never get to run because (.*) in first rule matched all requests.


RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L] 

spaceman813

4:44 pm on Jul 13, 2012 (gmt 0)

10+ Year Member



Thanks Wilderness, I understood which rules he was talking about (first, second...). What I didn't understand is how I should change them.
(I have no idea what ^ means, what kohana_uri is, what (.*) does, what QSA is, I'm sorry, it's like greek to me)

lucy24

9:25 pm on Jul 13, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, you don't need to ask us, because the information is already out there.

Apache mod_rewrite: [httpd.apache.org...]

This in turn will point you toward at least one site on Regular Expressions. But you may need to find your own reference. Look at different sites and find one whose explanations you can understand. Don't try to learn everything at once.

^ means "begins with..." except in grouping brackets, where it means "does not include..."
$ means "ends with..." except in targets, where it combines with a number to mean "captured text".

And that's why you need to find a RegEx tutorial that you yourself are comfortable with ;)

I seriously doubt you need the [PT] flag, if only because people who get that far tend to know what they are doing. (In other words, I have never used it myself. You don't generally see it in shared hosting.)

spaceman813

9:37 am on Jul 14, 2012 (gmt 0)

10+ Year Member



Thank you Lucy.
I think I'll give up though and wait for Google to reindex the whole website (45000 urls). I feel like I have to learn Russian just to be able to say "hi, how are you?".

What's really frustrating is that in this thread [gallery.menalto.com...] on the Gallery 3 forum, a solution was given to someone in my situation and he said "Thank you, it worked straight away!" but it doesn't for me! So I thought I was very close to fix it, but I've spent 2 days trying and trying with no success.