Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,093
    Thanks
    15
    Thanked 1 Time in 1 Post

    htaccess RewriteRule to redirect from a directory that doesn't exist

    I am attempting to redirect any URLs that attempt to access a directory that doesn't exist, however I am getting a 404 when trying the following:

    RewriteRule ^picco/(.*)$ /rangers/$1 [L,R=301]
    There is no directory called picco (it used to exist) however, when anyone tries to access a page picco/index.php for example I want to redirect to rangers/index.php.

    Is this possible?

  • #2
    Regular Coder
    Join Date
    Mar 2011
    Posts
    148
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Hi,
    Try this rewrite rule:
    Code:
    RewriteRule ^picco/([A-Za-z0-9_\.-]+)$ rangers/$1 [R=301]
    Or this:
    Code:
    RewriteRule ^(.*)picco/([A-Za-z_0-9\.-]+)$ http://www.domain.net/rangers/$2 [R=301]

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,093
    Thanks
    15
    Thanked 1 Time in 1 Post
    Thanks.

    This also worked:

    RewriteBase /
    RewriteRule ^picco(.*)$ /rangers/$1 [R=301,L]


  •  

    Tags for this Thread

    Posting Permissions

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