Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2006
    Posts
    984

    htaccess 301 redirect page

    Hi,

    I'm trying to redirect index.php to search.php?search_new_images=1 from htaccess instead of using header("Location: ...).

    Now, I do have SEO implemented from search.php to read search.htm . Is there a way to redirect without affecting the SEO once we type the query ?

  2. #2
    You can try by putting this in the .htaccess of the corresponding directory.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} index.php$
    RewriteRule ^(.*)$ search.php$1 [R=301,L]
    </IfModule>

  3. #3
    Join Date
    Mar 2006
    Posts
    984
    Sorry. This code shows the real unix path from query and index.phpsearch.php are sticked together. Any other solutions ... ?

  4. #4
    Join Date
    Mar 2006
    Posts
    984
    This issue has now been resolved by Googling a little bit more.

  5. #5
    Join Date
    Aug 2010
    Location
    Brussels, Belgium
    Posts
    162
    RewriteRule ^(.*)$ /search.php$1 [R=301,L]

    will solve the problem of the Linux path (mind the added slash).

    Jean-Luc

  6. #6
    Join Date
    Aug 2008
    Location
    In the shell...
    Posts
    90

    Try using this code for htaccess redirect

    Hello Horizon,

    Try using this code for htaccess redirect.Please add the destination URL.

    Code:
        Redirect index.php http://destination URL

  7. #7
    Join Date
    Mar 2006
    Posts
    984
    Since I already confirmed the first time that all is working, I thank both of you for helping me so far.

    However, I do have another question. Is there a way to replace %26 and %20 into their appropriate characters from URL by using htaccess ?

  8. #8
    Join Date
    Aug 2010
    Location
    Brussels, Belgium
    Posts
    162
    You should replace these codes by the characters they replace: replace %20 by a space character and replace %26 by &.

    Use double quotes around the part including the space character. Example:
    Code:
    redirect 301 "/space included/" http://www.example.com/
    If you are using regular expressions, I am not sure you can use the space as above with the double quotes. A workaround it to replace the space by \s.

    Jean-Luc

  9. #9
    Yes adding the slash before the search.php should solve the problem.

  10. #10
    Join Date
    Mar 2006
    Posts
    984
    Quote Originally Posted by 200-ok View Post
    You should replace these codes by the characters they replace: replace %20 by a space character and replace %26 by &.

    Use double quotes around the part including the space character. Example:
    Code:
    redirect 301 "/space included/" http://www.example.com/
    If you are using regular expressions, I am not sure you can use the space as above with the double quotes. A workaround it to replace the space by \s.

    Jean-Luc
    I'm not sure I do understand these instructions ... would it be possible to elaborate that a little ?

  11. #11
    Join Date
    Aug 2010
    Location
    Brussels, Belgium
    Posts
    162
    Example 1

    If you want to redirect a directory named /bla%20blabla/, you cannot use
    Code:
    redirect 301 /bla%20blabla/ http://www.example.com/
    But you can use
    Code:
    redirect 301 "/bla blabla/" http://www.example.com/
    Example 2

    If you use regular expressions, you cannot use
    Code:
    RewriteRule ^bla%20blablabla/(.*)$ more.php/$1 [R=301,L]
    But you can use
    Code:
    RewriteRule ^bla\sblablabla/(.*)$ more.php/$1 [R=301,L]
    Sorry for my sometimes chaotic English.

    Jean-Luc

  12. #12
    Join Date
    Mar 2006
    Posts
    984
    Quote Originally Posted by 200-ok View Post
    Example 1

    If you want to redirect a directory named /bla%20blabla/, you cannot use
    Code:
    redirect 301 /bla%20blabla/ http://www.example.com/
    But you can use
    Code:
    redirect 301 "/bla blabla/" http://www.example.com/
    Example 2

    If you use regular expressions, you cannot use
    Code:
    RewriteRule ^bla%20blablabla/(.*)$ more.php/$1 [R=301,L]
    But you can use
    Code:
    RewriteRule ^bla\sblablabla/(.*)$ more.php/$1 [R=301,L]
    Sorry for my sometimes chaotic English.

    Jean-Luc
    That's the easy actually. Instead, is there a standard way with RewriteRule to track if there's a space then to automatically replace it ?

    With php, there are multiple ways to do this. Is it doable with htaccess ?

Similar Threads

  1. 301 htaccess redirect exeptions?
    By lexington in forum Programming Discussion
    Replies: 1
    Last Post: 06-29-2008, 08:20 AM
  2. 301 redirect with .htaccess
    By GreatDomainRace in forum Hosting Security and Technology
    Replies: 3
    Last Post: 07-12-2007, 09:23 PM
  3. Help with 301 Redirect in .htaccess plz ?
    By Joel Theodore in forum Hosting Security and Technology
    Replies: 3
    Last Post: 02-27-2007, 06:53 PM
  4. htaccess redirect 301
    By WebPhaser in forum Web Design and Content
    Replies: 3
    Last Post: 12-30-2005, 02:37 PM
  5. 301 redirect in htaccess question
    By netcheap.com in forum Programming Discussion
    Replies: 5
    Last Post: 07-06-2005, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •