SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to alias a folder like this?

    Struggling trying to find out if this is even possible. I have a folder that contains a 'mini site' on a website (actually 38 of them), these mini site folders are located in a folder called 'sites'. We did this because when the site was bought these folders were all over the root (along with a thousand other nonsense files) and we needed to organize it some.

    Well the owner doesn't like the {domain}/sites/mini-site-folder/ layout and wants them to be {domain}/mini-sites-folder

    Now short of moving them all back to the root folder I can't seem to find a way to alias them so that {domain}/mini-sites-folder resolves to {domain}/sites/mini-site-folder/ I asked my server guy to look at it and he tried for a few days but couldn't come up with anything.

    I'm pretty sure there is a way to do it because I've seen things like this done on other sites but for the life of me (and my server guy) I can't find it

    Any help would be appreciated .... I shudder at the thought of moving them all back into the root

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Dave,

    mod_alias will do that for you as well as mod_rewrite. If it weren't for the obvious misdirections that would occur with mod_alias (unless there are no "normal," i.e., non mini-site subdirectories), your best bet would be to use mod_rewrite to CHECK whether the {REQUEST_FILENAME} exists as a file or directory then (if NOT) internally redirect to the sites subdirectory with the {REQUEST_URI}.

    In code terms:
    Code:
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # prevent this causing a loop
    RewriteCond %{REQUEST_URI} !^sites/
    RewriteRule .? sites%{REQUEST_URI} [L]
    Regards,

    DK
    Last edited by dklynn; Jul 15, 2010 at 14:47. Reason: Loopy, not 404 as previously stated
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Dave,

    mod_alias will do that for you as well as mod_rewrite. If it weren't for the obvious misdirections that would occur with mod_alias (unless there are no "normal," i.e., non mini-site subdirectories), your best bet would be to use mod_rewrite to CHECK whether the {REQUEST_FILENAME} exists as a file or directory then (if NOT) internally redirect to the sites subdirectory with the {REQUEST_URI}.

    In code terms:
    Code:
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # prevent this causing a loop
    RewriteCond %{REQUEST_URI} !^sites/
    RewriteRule .? sites%{REQUEST_URI} [L]
    Regards,

    DK
    Hmm, is that code 'literal', in the sense it should work as is because it's causing a server error for me
    Last edited by dklynn; Jul 15, 2010 at 14:47. Reason: Loopy, not 404 as previously stated

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,033
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by dc dalton View Post
    Hmm, is that code 'literal', in the sense it should work as is because it's causing a server error for me
    If you don't have it yet, the first line should be RewriteEngine On, all the rest should work as is
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Dave,

    Yes, that should work exactly as I had it ... IF mod_rewrite is enabled. Oh, it would be loopy, not 404, if the last RewriteCond was absent.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Dave,

    Yes, that should work exactly as I had it ... IF mod_rewrite is enabled. Oh, it would be loopy, not 404, if the last RewriteCond was absent.

    Regards,

    DK
    First off thanks for the time, learning some new stuff here that is really cool!

    Found out why I was blowing the server up and fixed that, have some of it working with the following exceptions (bare with me a bit)

    1. I have a multitude of 301 redirects on this mess and most are working, example:

    Code:
    RedirectMatch 301 /pipecreek/ /pipe-creek-guide-service/
    RedirectMatch 301 /pipecreek /pipe-creek-guide-service/
    But then I have some that throw an error, example:

    Code:
    RedirectMatch 301 /hollis/ /hollis-farms/
    RedirectMatch 301 /hollis /hollis-farms/
    Error is:

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
    It dawned on me after testing that the old folder (hollis) is the first word in the new folder and every one that is like that throws the same error. The ones (like the working one above) had a goofy folder name like pipecreek or dht, or hht) .... that first word in the new folder name no longer exists so the new rewrite condition and rule you posted works as expected.

    2. When nothing is found (for example adding gibberish to the url) example:

    http://localhost/rrreoirthwerhiew

    I get an internal server error. This bothers me because there are many pages that no longer exist and we want a 404 to be thrown. Is there a 'graceful' way to send them to a 404 page that can be added to your code?

    And just so you are getting the entire picture here is the complete htaccess file:

    Code:
    RedirectMatch 301 /brochure.htm /advertise-with-hunt-info
    RedirectMatch 301 /chopblock.htm /wild-game-meat-care
    RedirectMatch 301 /recipes.htm /venison-recipes
    RedirectMatch 301 /o&g.htm /outfitters-guides-listing
    RedirectMatch 301 /reviews.htm /outfitter-guides-product-reviews
    RedirectMatch 301 /state.htm /state-regional-hunting-info
    RedirectMatch 301 /links.htm /hunting-information-links
    RedirectMatch 301 /aboutus.htm /about-hunt-info
    RedirectMatch 301 /products.htm /hunting-gear-reviews
    RedirectMatch 301 /fields1.htm /field-dressing-deer
    RedirectMatch 301 /OK /oklahoma-outfitter-guide-reviews
    RedirectMatch 301 /NV /nevada-outfitter-guide-reviews
    RedirectMatch 301 /MT /montana-outfitter-guide-reviews
    RedirectMatch 301 /AK /alaska-outfitter-guide-reviews
    RedirectMatch 301 /OH /ohio-outfitter-guide-reviews
    RedirectMatch 301 /IL /illinois-outfitter-guide-reviews
    RedirectMatch 301 /NJ /new-jersey-outfitter-guide-reviews
    RedirectMatch 301 /reviews/product_reviews.php /hunting-gear-reviews
    RedirectMatch 301 /reviews/outfitter_submit.php /submit-outfitter-review
    RedirectMatch 301 /GA /georgia-outfitter-guide-reviews
    RedirectMatch 301 /CO /colorado-outfitter-guide-reviews
    RedirectMatch 301 /AR /arkansas-outfitter-guide-reviews
    RedirectMatch 301 /MD /maryland-outfitter-guide-reviews
    RedirectMatch 301 /NY /new-york-outfitter-guide-reviews
    RedirectMatch 301 /ND /north-dakota-outfitter-guide-reviews
    RedirectMatch 301 /ME /maine-outfitter-guide-reviews
    RedirectMatch 301 /LA /louisiana-outfitter-guide-reviews
    RedirectMatch 301 /KS /kansas-outfitter-guide-reviews
    RedirectMatch 301 /NE /nebraska-outfitter-guide-reviews
    RedirectMatch 301 /DE /delaware-outfitter-guide-reviews
    RedirectMatch 301 /CT /connecticut-outfitter-guide-reviews
    RedirectMatch 301 /MS /mississippi-outfitter-guide-reviews
    RedirectMatch 301 /MI /michigan-outfitter-guide-reviews
    RedirectMatch 301 /AZ /arizona-outfitter-guide-reviews
    RedirectMatch 301 /MN /minnesota-outfitter-guide-reviews
    RedirectMatch 301 /MO /missouri-outfitter-guide-reviews
    RedirectMatch 301 /SC /south-carolina-outfitter-guide-reviews
    RedirectMatch 301 /CA /california-outfitter-guide-reviews
    RedirectMatch 301 /AL /alabama-outfitter-guide-reviews
    RedirectMatch 301 /IA /iowa-outfitter-guide-reviews
    RedirectMatch 301 /FL /florida-outfitter-guide-reviews
    RedirectMatch 301 /MA /massachusetts-outfitter-guide-reviews
    RedirectMatch 301 /HI /hawaii-outfitter-guide-reviews
    RedirectMatch 301 /NM /new-mexico-outfitter-guide-reviews
    RedirectMatch 301 /NH /new-hampshire-outfitter-guide-reviews
    RedirectMatch 301 /KY /kentucky-outfitter-guide-reviews
    RedirectMatch 301 /IN /indiana-outfitter-guide-reviews
    RedirectMatch 301 /NC /north-carolina-outfitter-guide-reviews
    RedirectMatch 301 /ID /idaho-outfitter-guide-reviews
    RedirectMatch 301 /copyright.htm /huntinfo-terms-conditions
    
    RedirectMatch 301 /whitetailwishes/ /whitetail-wishes-outfitters/
    RedirectMatch 301 /whitetailwishes /whitetail-wishes-outfitters/
    RedirectMatch 301 /tickridge/ /tick-ridge-outfitters/
    RedirectMatch 301 /tickridge /tick-ridge-outfitters/
    RedirectMatch 301 /wyoedge/ /wyoming-edge-outfitters/
    RedirectMatch 301 /wyoedge /wyoming-edge-outfitters/
    RedirectMatch 301 /406/ /406-ranch/
    RedirectMatch 301 /allseasons/ /all-seasons-guide-service/
    RedirectMatch 301 /allseasons /all-seasons-guide-service/
    RedirectMatch 301 /rro/ /racoon-river-outfitters/
    RedirectMatch 301 /rro /racoon-river-outfitters/
    RedirectMatch 301 /westernmt/ /western-montana-guide-school/
    RedirectMatch 301 /westernmt /western-montana-guide-school/
    RedirectMatch 301 /royaltine/ /royal-tine-outfitter-guide-school/
    RedirectMatch 301 /royaltine /royal-tine-outfitter-guide-school/
    RedirectMatch 301 /riverview/ /river-view-lodge/
    RedirectMatch 301 /riverview /river-view-lodge/
    RedirectMatch 301 /pcrossbar/ /p-cross-bar/
    RedirectMatch 301 /pcrossbar /p-cross-bar/
    RedirectMatch 301 /lonestar/ /lone-star-ranch/
    RedirectMatch 301 /lonestar /lone-star-ranch/
    RedirectMatch 301 /etom/ /edmund-tom-ranch/
    RedirectMatch 301 /etom /edmund-tom-ranch/
    RedirectMatch 301 /dodgecreek/ /dodge-creek-ranch-wyoming/
    RedirectMatch 301 /dodgecreek /dodge-creek-ranch-wyoming/
    RedirectMatch 301 /bearpaw.htm /bearpaw-outfitters/
    RedirectMatch 301 /huntoncreek/ /hunton-creek-outfitters/
    RedirectMatch 301 /huntoncreek /hunton-creek-outfitters/
    RedirectMatch 301 /fwc/ /flat-willow-creek-outfitters/
    RedirectMatch 301 /fwc /flat-willow-creek-outfitters/
    RedirectMatch 301 /hht/ /hog-hunting-texas/
    RedirectMatch 301 /hht /hog-hunting-texas/
    RedirectMatch 301 /dht/ /deer-hunting-texas/
    RedirectMatch 301 /dht /deer-hunting-texas/
    RedirectMatch 301 /yo/ /yellowstone-outfitters/
    RedirectMatch 301 /yo /yellowstone-outfitters/
    RedirectMatch 301 /lazyhco/ /lazy-h-meadows-colorado/
    RedirectMatch 301 /lazyhco /lazy-h-meadows-colorado/
    RedirectMatch 301 /lazyhia/ /lazy-h-meadows-iowa/
    RedirectMatch 301 /lazyhia /lazy-h-meadows-iowa/
    RedirectMatch 301 /pipecreek/ /pipe-creek-guide-service/
    RedirectMatch 301 /pipecreek /pipe-creek-guide-service/
    RedirectMatch 301 /pipecreek2/ /pipe-creek-buffalo-hunts/
    RedirectMatch 301 /pipecreek2 /pipe-creek-buffalo-hunts/
    
    
    RedirectMatch 301 /hollis/ /hollis-farms/
    RedirectMatch 301 /hollis /hollis-farms/
    RedirectMatch 301 /jakes/ /jakes-rio-grande-outfitting/
    RedirectMatch 301 /jakes /jakes-rio-grande-outfitting/
    RedirectMatch 301 /abc/ /abc-ranch-ny/
    RedirectMatch 301 /abc /abc-ranch-ny/
    RedirectMatch 301 /powder/ /powder-river-bowhunts/
    RedirectMatch 301 /powder /powder-river-bowhunts/
    RedirectMatch 301 /jn/ /jn-ranch/
    RedirectMatch 301 /jn /jn-ranch/
    RedirectMatch 301 /hidden/ /hidden-valley-outfitters/
    RedirectMatch 301 /hidden /hidden-valley-outfitters/
    RedirectMatch 301 /elm/ /elm-outfitter-guide-training/
    RedirectMatch 301 /elm /elm-outfitter-guide-training/
    
    
    RewriteEngine on
    Options +FollowSymlinks
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # prevent this causing a loop
    RewriteCond %{REQUEST_URI} !^sites/
    RewriteRule .? sites%{REQUEST_URI} [L]
    
    # If the URI doesn't end with .js and .jpeg and .jpg and .gif and .css or any others
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|shtml|pdf|zip|htm)$ [NC]
    
    # apply transformations
    
    RewriteRule ^([^/]+)$ index.php?pageName=$1 [L]
    
    
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|pdf|zip|htm)$ [NC]
    
    RewriteRule ^([^/]+)/([^/]+)$ index.php?pageName=$1&id=$2 [L]
    [edit]

    Crap, just noticed another error that's happening ..... my rewrite (for the site pages) is throwing an internal server error for everything. It seems to work if I move your code after mine but will have to do more testing to make sure.

  7. #7
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was able to solve the internal server error when nothing was found (my gibberish url above) and the problem of my rewrite not working for the site pages by moving your condition after mine .... making progress here.

    Code:
    RedirectMatch 301 /brochure.htm /advertise-with-hunt-info
    RedirectMatch 301 /chopblock.htm /wild-game-meat-care
    RedirectMatch 301 /recipes.htm /venison-recipes
    RedirectMatch 301 /o&g.htm /outfitters-guides-listing
    RedirectMatch 301 /reviews.htm /outfitter-guides-product-reviews
    RedirectMatch 301 /state.htm /state-regional-hunting-info
    RedirectMatch 301 /links.htm /hunting-information-links
    RedirectMatch 301 /aboutus.htm /about-hunt-info
    RedirectMatch 301 /products.htm /hunting-gear-reviews
    RedirectMatch 301 /fields1.htm /field-dressing-deer
    RedirectMatch 301 /OK /oklahoma-outfitter-guide-reviews
    RedirectMatch 301 /NV /nevada-outfitter-guide-reviews
    RedirectMatch 301 /MT /montana-outfitter-guide-reviews
    RedirectMatch 301 /AK /alaska-outfitter-guide-reviews
    RedirectMatch 301 /OH /ohio-outfitter-guide-reviews
    RedirectMatch 301 /IL /illinois-outfitter-guide-reviews
    RedirectMatch 301 /NJ /new-jersey-outfitter-guide-reviews
    RedirectMatch 301 /reviews/product_reviews.php /hunting-gear-reviews
    RedirectMatch 301 /reviews/outfitter_submit.php /submit-outfitter-review
    RedirectMatch 301 /GA /georgia-outfitter-guide-reviews
    RedirectMatch 301 /CO /colorado-outfitter-guide-reviews
    RedirectMatch 301 /AR /arkansas-outfitter-guide-reviews
    RedirectMatch 301 /MD /maryland-outfitter-guide-reviews
    RedirectMatch 301 /NY /new-york-outfitter-guide-reviews
    RedirectMatch 301 /ND /north-dakota-outfitter-guide-reviews
    RedirectMatch 301 /ME /maine-outfitter-guide-reviews
    RedirectMatch 301 /LA /louisiana-outfitter-guide-reviews
    RedirectMatch 301 /KS /kansas-outfitter-guide-reviews
    RedirectMatch 301 /NE /nebraska-outfitter-guide-reviews
    RedirectMatch 301 /DE /delaware-outfitter-guide-reviews
    RedirectMatch 301 /CT /connecticut-outfitter-guide-reviews
    RedirectMatch 301 /MS /mississippi-outfitter-guide-reviews
    RedirectMatch 301 /MI /michigan-outfitter-guide-reviews
    RedirectMatch 301 /AZ /arizona-outfitter-guide-reviews
    RedirectMatch 301 /MN /minnesota-outfitter-guide-reviews
    RedirectMatch 301 /MO /missouri-outfitter-guide-reviews
    RedirectMatch 301 /SC /south-carolina-outfitter-guide-reviews
    RedirectMatch 301 /CA /california-outfitter-guide-reviews
    RedirectMatch 301 /AL /alabama-outfitter-guide-reviews
    RedirectMatch 301 /IA /iowa-outfitter-guide-reviews
    RedirectMatch 301 /FL /florida-outfitter-guide-reviews
    RedirectMatch 301 /MA /massachusetts-outfitter-guide-reviews
    RedirectMatch 301 /HI /hawaii-outfitter-guide-reviews
    RedirectMatch 301 /NM /new-mexico-outfitter-guide-reviews
    RedirectMatch 301 /NH /new-hampshire-outfitter-guide-reviews
    RedirectMatch 301 /KY /kentucky-outfitter-guide-reviews
    RedirectMatch 301 /IN /indiana-outfitter-guide-reviews
    RedirectMatch 301 /NC /north-carolina-outfitter-guide-reviews
    RedirectMatch 301 /ID /idaho-outfitter-guide-reviews
    RedirectMatch 301 /copyright.htm /huntinfo-terms-conditions
    
    RedirectMatch 301 /maplelane/ http://www.ashridgecabins.com/maplelaneop/
    
    RedirectMatch 301 /whitetailwishes/ /whitetail-wishes-outfitters/
    RedirectMatch 301 /whitetailwishes /whitetail-wishes-outfitters/
    RedirectMatch 301 /tickridge/ /tick-ridge-outfitters/
    RedirectMatch 301 /tickridge /tick-ridge-outfitters/
    RedirectMatch 301 /wyoedge/ /wyoming-edge-outfitters/
    RedirectMatch 301 /wyoedge /wyoming-edge-outfitters/
    RedirectMatch 301 /406/ /406-ranch/
    RedirectMatch 301 /allseasons/ /all-seasons-guide-service/
    RedirectMatch 301 /allseasons /all-seasons-guide-service/
    RedirectMatch 301 /rro/ /racoon-river-outfitters/
    RedirectMatch 301 /rro /racoon-river-outfitters/
    RedirectMatch 301 /westernmt/ /western-montana-guide-school/
    RedirectMatch 301 /westernmt /western-montana-guide-school/
    RedirectMatch 301 /royaltine/ /royal-tine-outfitter-guide-school/
    RedirectMatch 301 /royaltine /royal-tine-outfitter-guide-school/
    RedirectMatch 301 /riverview/ /river-view-lodge/
    RedirectMatch 301 /riverview /river-view-lodge/
    RedirectMatch 301 /pcrossbar/ /p-cross-bar/
    RedirectMatch 301 /pcrossbar /p-cross-bar/
    RedirectMatch 301 /lonestar/ /lone-star-ranch/
    RedirectMatch 301 /lonestar /lone-star-ranch/
    RedirectMatch 301 /etom/ /edmund-tom-ranch/
    RedirectMatch 301 /etom /edmund-tom-ranch/
    RedirectMatch 301 /dodgecreek/ /dodge-creek-ranch-wyoming/
    RedirectMatch 301 /dodgecreek /dodge-creek-ranch-wyoming/
    RedirectMatch 301 /bearpaw.htm /bearpaw-outfitters/
    RedirectMatch 301 /huntoncreek/ /hunton-creek-outfitters/
    RedirectMatch 301 /huntoncreek /hunton-creek-outfitters/
    RedirectMatch 301 /fwc/ /flat-willow-creek-outfitters/
    RedirectMatch 301 /fwc /flat-willow-creek-outfitters/
    RedirectMatch 301 /hht/ /hog-hunting-texas/
    RedirectMatch 301 /hht /hog-hunting-texas/
    RedirectMatch 301 /dht/ /deer-hunting-texas/
    RedirectMatch 301 /dht /deer-hunting-texas/
    RedirectMatch 301 /yo/ /yellowstone-outfitters/
    RedirectMatch 301 /yo /yellowstone-outfitters/
    RedirectMatch 301 /lazyhco/ /lazy-h-meadows-colorado/
    RedirectMatch 301 /lazyhco /lazy-h-meadows-colorado/
    RedirectMatch 301 /lazyhia/ /lazy-h-meadows-iowa/
    RedirectMatch 301 /lazyhia /lazy-h-meadows-iowa/
    RedirectMatch 301 /pipecreek/ /pipe-creek-guide-service/
    RedirectMatch 301 /pipecreek /pipe-creek-guide-service/
    RedirectMatch 301 /pipecreek2/ /pipe-creek-buffalo-hunts/
    RedirectMatch 301 /pipecreek2 /pipe-creek-buffalo-hunts/
    
    
    RedirectMatch 301 /hollis/ /hollis-farms/
    RedirectMatch 301 /hollis /hollis-farms/
    RedirectMatch 301 /jakes/ /jakes-rio-grande-outfitting/
    RedirectMatch 301 /jakes /jakes-rio-grande-outfitting/
    RedirectMatch 301 /abc/ /abc-ranch-ny/
    RedirectMatch 301 /abc /abc-ranch-ny/
    RedirectMatch 301 /powder/ /powder-river-bowhunts/
    RedirectMatch 301 /powder /powder-river-bowhunts/
    RedirectMatch 301 /jn/ /jn-ranch/
    RedirectMatch 301 /jn /jn-ranch/
    RedirectMatch 301 /hidden/ /hidden-valley-outfitters/
    RedirectMatch 301 /hidden /hidden-valley-outfitters/
    RedirectMatch 301 /elm/ /elm-outfitter-guide-training/
    RedirectMatch 301 /elm /elm-outfitter-guide-training/
    
    
    RewriteEngine on
    Options +FollowSymlinks
    
    # If the URI doesn't end with .js and .jpeg and .jpg and .gif and .css or any others
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|shtml|pdf|zip|htm)$ [NC]
    
    # apply transformations
    
    RewriteRule ^([^/]+)$ index.php?pageName=$1 [L]
    
    
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|pdf|zip|htm)$ [NC]
    
    RewriteRule ^([^/]+)/([^/]+)$ index.php?pageName=$1&id=$2 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # prevent this causing a loop
    RewriteCond %{REQUEST_URI} !^sites/
    RewriteRule .? sites%{REQUEST_URI} [L]

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Dave,

    No problem! That's what I'm here for (to help others learn).

    Do you have access to httpd.conf (actually, the httpd-vhosts.conf for your domain)? If so, move all the Redirects that work there so they're only read once (rather than for EVERY @#$% file request!).

    How is RedirectMatch 301 /hollis /hollis-farms/ supposed to tell hollis{followed by anything} from hollis-farms? Admittedly, I see your mod_alias directive with my mod_rewrite (regex) blinders on but it looks like it should be loopy!

    "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

    That's what I'd expect.

    Since you have that for (all?) your RedirectMatch statements, I'm shocked that your Apache hasn't packed up its teepee and headed for the Great Plains!
    It dawned on me after testing that the old folder (hollis) is the first word in the new folder and every one that is like that throws the same error. The ones (like the working one above) had a goofy folder name like pipecreek or dht, or hht) .... that first word in the new folder name no longer exists so the new rewrite condition and rule you posted works as expected.
    Okay, you found that problem, too!

    Next, do you really expect rrreoirthwerhiew NOT to be matched by
    Code:
    RewriteEngine on
    Options +FollowSymlinks
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # prevent this causing a loop
    RewriteCond %{REQUEST_URI} !^sites/
    RewriteRule .? sites%{REQUEST_URI} [L]
    
    # If the URI doesn't end with .js and .jpeg and .jpg and .gif and .css or any others
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|shtml|pdf|zip|htm)$ [NC]
    
    # apply transformations
    
    RewriteRule ^([^/]+)$ index.php?pageName=$1 [L]
    Note that BOTH red bits WILL match rrreoirthwerhiew with the sites/rrreoirthwerhiew taking precedence (order) at which time
    Code:
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|pdf|zip|htm)$ [NC]
    
    RewriteRule ^([^/]+)/([^/]+)$ index.php?pageName=$1&id=$2 [L]
    will kick-in and redirect to index.php with sites as the pageName value and id=rrreoirthwerhiew! If index.php can't handle that jibberish, you're in real trouble!
    Quote Originally Posted by dc dalton View Post
    I was able to solve the internal server error when nothing was found (my gibberish url above) and the problem of my rewrite not working for the site pages by moving your condition after mine .... making progress here.
    Does that mean you've fixed it the way you need?

    IMHO, you need to "trim" your .htaccess to something more reasonable else you'll be burdening your server far too much with every file request.

    Then think like mod_rewrite and "see" how each request is handled - remembering to follow the redirections through the next loop (mod_rewrite keeps looping back through until no more redirections are found/executed).

    What you've encountered is similar to the problem that noobies have when they use (.*) to match (NOTHING or EVERYTHING) and wonder why their redirections never end (go loopy). If you're as exact as possible in defining the {REQUEST_URI} string which you need to be redirected, that tends to avoid the loop problem.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Dave,

    No problem! That's what I'm here for (to help others learn).

    Do you have access to httpd.conf (actually, the httpd-vhosts.conf for your domain)? If so, move all the Redirects that work there so they're only read once (rather than for EVERY @#$% file request!).
    Yes once we get all the issues solved it will all get neatly packed in the config file.

    Quote Originally Posted by dklynn View Post
    How is RedirectMatch 301 /hollis /hollis-farms/ supposed to tell hollis{followed by anything} from hollis-farms? Admittedly, I see your mod_alias directive with my mod_rewrite (regex) blinders on but it looks like it should be loopy!

    "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

    That's what I'd expect.
    So basically you are saying those couple are no gos?

    Quote Originally Posted by dklynn View Post
    Since you have that for (all?) your RedirectMatch statements, I'm shocked that your Apache hasn't packed up its teepee and headed for the Great Plains!
    Quote Originally Posted by dklynn View Post
    Next, do you really expect rrreoirthwerhiew NOT to be matched by
    Code:
    RewriteEngine on
    Options +FollowSymlinks
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # prevent this causing a loop
    RewriteCond %{REQUEST_URI} !^sites/
    RewriteRule .? sites%{REQUEST_URI} [L]
    
    # If the URI doesn't end with .js and .jpeg and .jpg and .gif and .css or any others
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|shtml|pdf|zip|htm)$ [NC]
    
    # apply transformations
    
    RewriteRule ^([^/]+)$ index.php?pageName=$1 [L]
    Note that BOTH red bits WILL match rrreoirthwerhiew with the sites/rrreoirthwerhiew taking precedence (order) at which time
    Code:
    RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|pdf|zip|htm)$ [NC]
    
    RewriteRule ^([^/]+)/([^/]+)$ index.php?pageName=$1&id=$2 [L]
    will kick-in and redirect to index.php with sites as the pageName value and id=rrreoirthwerhiew! If index.php can't handle that jibberish, you're in real trouble!

    Does that mean you've fixed it the way you need?
    I have fixed the internal server error problems by moving your code below mine, my PHP handler grabs it and shows on of my error pages


    Quote Originally Posted by dklynn View Post
    IMHO, you need to "trim" your .htaccess to something more reasonable else you'll be burdening your server far too much with every file request.
    Yes we know it is huge and burdensome but it will be moved to the config file once testing is done ... the problem here is we are trying to 'fix' a site that has been an utter disaster since it was created in 1996, this guy just piled more and more crap on in any way shape or form he could .... now the real problem is the site has some amazing rankings (why it was bought by my client)

    Quote Originally Posted by dklynn View Post

    Then think like mod_rewrite and "see" how each request is handled - remembering to follow the redirections through the next loop (mod_rewrite keeps looping back through until no more redirections are found/executed).

    What you've encountered is similar to the problem that noobies have when they use (.*) to match (NOTHING or EVERYTHING) and wonder why their redirections never end (go loopy). If you're as exact as possible in defining the {REQUEST_URI} string which you need to be redirected, that tends to avoid the loop problem.

    Regards,

    DK
    Will have to 'ponder the masters words' on that last bit


Bookmarks

Posting Permissions

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