SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  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)

    .htaccess 301 redirect and then another redirect ... need to stop this

    I'm at the end of fixing what was an abomination of a website, don't even want to go into the mess the old developer had going but trust me it was bad.

    So anyway, I have to do 301 redirects on what pages were indexed by the SEs to the new SE friendly URLs but I also run a mod_rewrite on my page names to 'flip' them into my PHP properly. For that 'onsite' rewriting I use this:

    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)$ [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)$ [NC]

    RewriteRule ^([^/]+)/([^/]+)$ index.php?pageName=$1&outfitter_id=$2 [L]
    Now the 301 redirects are before the above code like this:

    RedirectMatch 301 /outfitter.php/AK /Alaska-Hunting-Outfitters
    But when I click on a link from Google I end up with a URL that looks like this:

    /New-Jersey-Hunting-Outfitters?pageName=outfitter.php&outfitter_id=NJ
    I'm not 100% sure why this is happening and honestly have no clue how to fix it.

    Of course this will only happen until Google deletes the old indexed pages from their system but who knows how long that could take.

    Any help would be appreciated!

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

    mod_alias takes precedence over mod_rewrite so it will ALWAYS be executed first (ergo, the reason for RewriteBase). However, if you're going to make CONFLICTING redirects (mod_alias and mod_rewrite), then you must expect such conflicts.

    There MIGHT be a way around this BECAUSE you infer a change in PAGE file extension. Rather than exclude a series of filename extensions WHILE ALLOWING the dot character ([^/]+ ONLY disallows the slash character), specify that you will only redirect on \.html.

    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

  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
    dc,

    mod_alias takes precedence over mod_rewrite so it will ALWAYS be executed first (ergo, the reason for RewriteBase). However, if you're going to make CONFLICTING redirects (mod_alias and mod_rewrite), then you must expect such conflicts.

    There MIGHT be a way around this BECAUSE you infer a change in PAGE file extension. Rather than exclude a series of filename extensions WHILE ALLOWING the dot character ([^/]+ ONLY disallows the slash character), specify that you will only redirect on \.html.

    Regards,

    DK
    hmm, I almost understand what you are saying but by redirecting on the dot character (or redirecting on .php) I'm afraid I am going to cause issues with the site ... there are places where .php URLs will not be re-directed.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    DC,
    Quote Originally Posted by dc dalton View Post
    hmm, I almost understand what you are saying but by redirecting on the dot character (or redirecting on .php) I'm afraid I am going to cause issues with the site ... there are places where .php URLs will not be re-directed.
    In that case, you've not given the whole specification and I've mis-interpreted your needs. Better spec, though, sounds like it might be impossible under your circumstances. Perhaps creating a 404 file (rather than use mod_rewrite) for your replaced files (fetch and parse {THE_REQUEST} for the name of the requested file which wasn't found then pull from a db what the new file is and use PHP's header("Location:...") function with a 301 code.

    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


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
  •