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.
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 @ http://stackoverflow.com/questions/723283/wordpress-modrewrite with no joy.
Please help! :)
any ideas?
-
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>
cosmicbdog : That makes sense. Elsewhere I've read that the custom rules need to be added before the Wordpress begins. On the linked examples above theirs are before. I tried putting it below just now but it doesn't like me :( Thanks anyways ! -
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]
cosmicbdog : Tried this with fingers crossed and no cigar :| Thanks anyways Gumbo.Gumbo : Did you try it with a relative path? -
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.
-
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>
cosmicbdog : THANKS chris very helpful.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.