SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding custom htaccess redirect rules question

    Hi

    I have the following .htaccess file:

    Code:
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /page.php [L]
    
    RewriteCond %{HTTP_HOST} !^www.domain.com$
    RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [L,R=301]
    and I would like to add this line, but can't get it work anywhere in the file. Any ideas?

    Code:
    RewriteRule account/(.*) step2.php?package=$1 [NC,L]

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,265
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Given what you've shown, it should work as the first rewrite rule.

    Code:
    RewriteEngine on
    
    RewriteRule account/(.*) step2.php?package=$1 [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /page.php [L]
    
    RewriteCond %{HTTP_HOST} !^www.domain.com$
    RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [L,R=301]
    I copy-pasted your code to double check, and this works for me.
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Jeff,

    I tried adding it at the top as shown in the last post but it still doesn't redirect for me...

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

    Try:

    Code:
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} !^www.domain.com$
    RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301]
    
    RewriteRule account/(.*) step2.php?package=$1 [L] # Do not use NC in a RewriteRule
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? page.php [L] # No need to specify DocumentRoot when you're in the DocumentRoot
    
    RewriteCond %{THE_REQUEST} .+/index\.php # Overly complex for no reason; require at least one char before index.php
    RewriteRule ^(.*)index\.php$ /$1 [L,R=301] # Why not display the DirectoryIndex? The reason for this baffles me.
    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

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK,

    Thanks - but the issue still persists. The link I want to redirect is:

    http://www.domain.com/account/Bronze

    should go to:

    http://www.domain.com/step2.php?package=Bronze

    I tried the code you posted but still doesn't work strange.

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,265
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    There must be something more going on than what you've shown us. Other htaccess or other configuration.
    "First make it work. Then make it better."

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

    That's strange, indeed! There is nothing to redirect FROM step2.php IF (and only if) step2.php exists.

    Code:
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} !^www.domain.com$
    RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301]
    # Does not change {REQUEST_URI}
    
    RewriteRule account/(.*) step2.php?package=$1 [L] # Do not use NC in a RewriteRule
    # Will match account/Bronze and redirect to step2.php?package=Bronze
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? page.php [L] # No need to specify DocumentRoot when you're in the DocumentRoot
    # Will not redirect step2.php to page.php IF (and only if) step2.php does not exist (as a file or as a directory)
    
    RewriteCond %{THE_REQUEST} .+/index\.php # Overly complex for no reason; require at least one char before index.php
    RewriteRule ^(.*)index\.php$ /$1 [L,R=301] # Why not display the DirectoryIndex? The reason for this baffles me.
    # Ditto if {THE_REQUEST} and {REQUEST_URI} contains index.php, it will redirect but NOT if it's step2.php.
    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

  8. #8
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Z,

    That's strange, indeed! There is nothing to redirect FROM step2.php IF (and only if) step2.php exists.
    Hi,

    Sorry for the delayed reply.

    I tried the latest code but now it's giving a 500 internal server error. Not sure whats wrong now...


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
  •