How do you simply add new custom rewrites to the .htaccess of a wordpress without fail?

I’ve added some extra functionality to my wordpress so that I can visit it with a variable and do extra stuff.

The problem is, when I turn my ugly dynamic link into lovely permlink formatting in the .htaccess file, wordpress overrides it / ignores it. I’ve heard there’s a way to do it, but the ways I try to do it based off what people have said still returns a 404 page regardless. I know that the file its pointing to works.

Read More

2 ways ppl say works but I’ve had no joy with:

1) insert the rules above the #BEGIN wordpress part
2) use add_rewrite_rule() wordpress function somewhere

Has anybody had any success with these methods? or other methods?

Here’s what my .htaccess file looks like

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC]
</IfModule>


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


</IfModule>

In my themes function.php I’ve also tried adding:

add_rewrite_rule('/ref/(.*)$', 'index.php?ref=1&sid=$matches[1]','top');

With no success.

I’ve also tried the solutions over @ WordPress + mod_rewrite with no joy.

Please help! 🙂

any ideas?

Related posts

Leave a Reply

4 comments

  1. This works – I just tested it – Note I added an L to the end of the RewriteRule

    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC,L]
    
    #wp
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
  2. a new rule will always override the old ones

    try the following

    <IfModule mod_rewrite.c>
    RewriteEngine On
    #wp
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC]
    
    
    </IfModule>
    
  3. In .htaccess files you have to leave the leading slash in the patterns of the RewriteRule directive away. So try this:

    RewriteRule ^ref/(.*)$ index.php?ref=1&sid=$1 [NC]
    
  4. I wound up doing the following in php since the above solutions seemed to not work. WordPress rulership over the .htaccess file is supreme:

    if(strstr($_SERVER['REQUEST_URI'], '/ref/')) {
    

    And from that have been able to do fairly much the same stuff. A pretty url that translates into something else.