• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
htaccess redirect 301 single url

#1
[eluser]ironlung[/eluser]
Hi all I have the normal htaccess file for codeigniter and I want to 301 one url to another

ie http://www.domain.com/controller/method/value1
->http://www.domain.com/controller/method/value2

but I'm having a hell of a time...

Here's the htaccess
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^(home(/index)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]


#Removes trailing slashes
#had to remove ajaxquery search else it fails
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(search/ajaxsearch)
RewriteRule ^(.+)/$ $1 [L,R=301]


#Rewrite all non-www to www based filenames
#should get rid of any canonical issues
RewriteCond %{HTTP_HOST} ^domain\.es [NC]
RewriteRule ^(.*)$ http://www.doman\.es/$1 [R=301,L]


    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]



</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

#2
[eluser]ironlung[/eluser]
If I do this
Code:
Redirect 301 /controller/method/value1 http://www.domain.com/controller/method/value2

I get this

Code:
http://www.domain.com/controller/method/value2?controller/method/value1

which is whacky doodle dandy Smile

Edited to put missing leading slash in.

#3
[eluser]Aken[/eluser]
Try putting a slash at the start of your matched url, e.g.:

Code:
Redirect 301 /controller/method/value1 http://www.domain.com/controller/method/value2

#4
[eluser]ironlung[/eluser]
[quote author="Aken" date="1363135495"]Try putting a slash at the start of your matched url, e.g.:

Code:
Redirect 301 /controller/method/value1 http://www.domain.com/controller/method/value2
[/quote]

Damn there is a slash I made a copy paste error!

#5
[eluser]ironlung[/eluser]
Also tried this
http://stackoverflow.com/questions/14517...r-htaccess

ie.
Code:
RewriteRule ^/controller/method/value1$ /controller/method/value2 [R=301,L]

Just redirects to homepage Sad

I lose days of my life everytime I open this file Smile

#6
[eluser]TheFuzzy0ne[/eluser]
Please could you post the whole file again?

#7
[eluser]ironlung[/eluser]
[quote author="TheFuzzy0ne" date="1363163805"]Please could you post the whole file again?[/quote]

Sure I'm just changing the domain name...

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^(home(/index)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

#Removes trailing slashes
#had to remove ajaxquery search else it fails
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(search/ajaxsearch)
RewriteRule ^(.+)/$ $1 [L,R=301]

#Rewrite all non-www to www based filenames
#should get rid of any canonical issues
RewriteCond %{HTTP_HOST} ^domain\.es [NC]
RewriteRule ^(.*)$ http://www.domain\.es/$1 [R=301,L]

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]



</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

#8
[eluser]TheFuzzy0ne[/eluser]
Is this where you're stuck?
Code:
RewriteRule ^(home(/index)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

First of all, I would suggest you replace:
Code:
RewriteCond %{HTTP_HOST} ^domain\.es [NC]
RewriteRule ^(.*)$ http://www.domain\.es/$1 [R=301,L]

with a more generic:

Code:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

The next thing that glares at me is that you have this:
Code:
RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

Your rewrite rule for both should probably be either:
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]
[code]

or

[code]
RewriteRule ^(.*)$ /index.php?/$1 [L]

In theory, only one of those should actually work.

#9
[eluser]ironlung[/eluser]
Hey thanks for helping.

This worked great
Quote:
Code:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]



With these the first one put me on the 404 page
second one gave me an internal server error (I did of course replace the text you suggested)

Quote:
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]
[code]

or

[code]
RewriteRule ^(.*)$ /index.php?/$1 [L]

My real issue is that I cant make a single one page 301 redirect

Code:
Redirect 301 /controller/method/value1 http://www.domain.com/controller/method/value2

gives me this

Code:
http://www.domain.com/controller/method/value2?controller/method/value1

ie it query strings the first url... So weird.

#10
[eluser]TheFuzzy0ne[/eluser]
Does this not work?

Code:
RewriteCond %{REQUEST_URI} ^(/controller/method/value1)
RewriteRule ^(.*)$ /controller/method/value2 [L,R=301]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.