Support » Fixing WordPress » .htaccess – Is WP Killing My Rules?

  • I’m writing a plugin currently, and I’m needing to add a rule to my .htaccess file to complete its functionality. I’m trying to redirect requests from /go/alphanumericstring to /index.php?gocode=alphanumericstring. I’ve been trying to get my rewrite rule working for a couple hours now, but it’s still not working. Here’s my .htaccess file:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /sites/test-wp/
    RewriteRule ^go/([A-Za-z0-9]+)/?$ /index.php?gocode=$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /sites/test-wp/index.php [L]
    </IfModule>
    
    # END WordPress

    The bold line is the one that I am having trouble with. I’ve tried several iterations of it, moved it to different locations in the file, and even put it above the “Start WordPress” line (with a RewriteEngine On line, of course). Nothing is working.

    Does anyone have a solution?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    If you put rules inside the # BEGIN WordPress and # END WordPress lines, then yes, WordPress will remove them from time to time.

    Don’t put your rules inside those lines. Make your own rewrite section above the WordPress one and put your rule there instead.

    Thread Starter redwallhp

    (@redwallhp)

    I already tried that. WordPress isn’t removing the rules, but they’re just not working.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Ah. Well, in particular that “go” RewriteRule you have won’t work because you don’t have an [L] at the end of it.

    Thread Starter redwallhp

    (@redwallhp)

    Well, there’s some progress. The current iteration looks like this:

    RewriteEngine On
    RewriteBase /sites/test-wp/
    RewriteRule ^go/([A-Za-z0-9]+)/?$ /index.php?gocode=$1 [L]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /sites/test-wp/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /sites/test-wp/index.php [L]
    </IfModule>
    
    # END WordPress

    For some reason it’s bouncing requests to ntugo.com/index.php?gocode=$1 instead of ntugo.com/sites/test-wp/index.php?gocode=$1

    Why’s that?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    For some reason it’s bouncing requests to ntugo.com/index.php?gocode=$1 instead of ntugo.com/sites/test-wp/index.php?gocode=$1

    Why’s that?

    Err… Because that’s what you told it to do?

    RewriteRule ^go/([A-Za-z0-9]+)/?$ /index.php?gocode=$1 [L]

    Right there, you told it to go to /index.php. If you want it to go to /sites/test-wp/index.php, then your rule should have been:

    RewriteRule ^go/([A-Za-z0-9]+)/?$ /sites/test-wp/index.php?gocode=$1 [L]

    Thread Starter redwallhp

    (@redwallhp)

    Ah, thanks. Everything is working fine now.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘.htaccess – Is WP Killing My Rules?’ is closed to new replies.