PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1845
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Apache vhosts config RewriteCond to ignore part of URL Posted by crmpicco on 24 Sept 2012 at 7:01 AM
I am attempting to control redirections on my site using the Apache vhosts config.

I have two-letter regions setup, such as /fr, /de, /es, which I am currently ignoring as you will see from my vhosts file below. However I also have a 301 permanent redirect setup to redirect /cm (and /fr/cm, /es/cm etc) to another page - this is controlled in my back-end system.

The complication is when I add the line RewriteCond %{REQUEST_URI} !^/cm this is caught by the RewriteCond, however I then cannot access /fr, /de, /es etc at all as they seem to get stuck in a loop and go to: www.ayrshireminis.com/fr/fr/fr/fr/fr/fr/fr/fr and then it HTTP 500 Internal Server Errors.

How could I change the RewriteCond to allow for:

/pa (this will be redirected to /minis, but it is controlled in the database and needs to stay as a valid URL)
/fr (the region)
/fr/pa
/es/pa

etc.

Code:
    # ----------------------------------------------------------------------
    # REGION SPECIFIC REDIRECTIONS
    # Below will remove region specific part of URL and load content from main UK site
    # ----------------------------------------------------------------------
    RewriteCond             %{REQUEST_URI}                  ^/([a-z]{2})$                   [OR]
    RewriteCond             %{REQUEST_URI}                  ^/([a-z]{2}/)(.*)$
    RewriteCond             %{REQUEST_URI}                  !^/cm
    RewriteRule             ^([a-z]{2}/|[a-z]{2})(.*)$      /$2                                             [L,QSA]

    # For VirtualDocumentRoot development instance configurations
    RewriteRule ^([^.]+)$ /index.php?url=$1 [L,QSA]




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.