This is the first time I've used mod rewrite so it might just be because I've done something wrong. Here is my code to get started; Options +FollowSymLinks RewriteEngine on RewriteRule singlearticle/(.*)/(.*)/$ /singlearticle.php?$1=$2 Code (markup): I've placed this in the .htaccess file and mod rewrite is a loaded module on the server. Any ideas why this wouldn't turn the URL singlearticle.php?articleid=1 into /singlearticle/articleid/1/?
I think that you've got it twisted around. The code that you posted should turn /singlearticle/articleid/1/ into singlearticle.php?articleid=1, which is probably what you're aiming for if you're trying to make SE friendly URLs. cheers John
Well it's basically just to get me started. I really want to turn singlearticle.php?title=thistitle into /article/thistitle but I thought if I used the example above it would be a good place to start. Like I said I've never used mod rewrite before
Lets say I wanted to change domain.com/articles.php?articleid=1 into domain.com/articles/1/ what code would I be wanting to write into the .htaccess file?
Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} ^/articles/(.*)/ RewriteRule ^(.*)/ /articles\.php?articleid=%1 [L] Code (markup):
I think that you've got the code right, you just got the test wrong. If I read your post correctly, you put singlearticle.php?articleid=1 into your browser and it didn't get changed. Try using the same .htaccess and putting /singlearticle/articleid/1/ into your browser. I think that this is what you're trying to achieve - it will turn an ugly looking URL into something that looks good to both visitors and search engines cheers John
This is basically what the first 6 lines of my code looks like AddType text/css .css <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} ^/articles/(.*)/ RewriteRule ^(.*)/ /singlearticle\.php?articleid=%1 [L] and nothing happens if I put the URL in either way round. I'll PM you the URL.
Give this a go Options +FollowSymLinks RewriteEngine on RewriteRule ^singlearticle/(.*)/?$ /singlearticle.php?articleid=$1 Code (markup):
I'm not an expert on this but I muddled my way through on a new site and the above code works a treat for me with a slight variation
Hmm, I'm beginning to think that there's something obvious I'm missing out. The wordpress mod rewrite worked but this one isn't.
I think dct is right, I think that the RewriteBase directive is screwing it up. Just had a quick glance at the manual again, and I think that the RewriteBase refers to the physical path on the server, not the URL path. Try taking the RewriteBase out and I think it should be fine. cheers John
Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteRule articles/(.*)/$ articles.php?articleid=$1 [L] In the PM you gave me... www.domain.com/articles.php?articleid=1 into www.domain.com/articles/1/ If it is singlearticle.php, change articles.php to singlearticle.php
Thanks for all your help guys. It's still not working even trying all your solutions. I'm going to try it on a different server just in case it's a server problem. Will post here the results!
If you have domain.com/index.html for example, try this... Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^wacko.html$ index.html [L] and go to domain.com/wacko.html If that URL doesn't work, then you probably don't have .htaccess support. What kind of server are you on? I once tried it on a Windows server, er hacked in to MikeDammann's server (That's sitetutor for those of you in Rio Linda), and it didn't work.
Thats strange! I tried your example and it didn't work either yet the wordpress rewrites are working properly. According to phpinfo the mod_rewrite module is set up on the server.
Not in that part of the rule. You only need to escape the special characters in a pattern that you're trying to match, not in the string that you're turning it into
Thanks john for sorting out the rewriterule. At first I thought that the mod rewrite redirects the URL to the rewritten URL. Is this not the case? I can see that when you type both URL's in you get the same page.
mod_rewrite doesn't affect the rewritten URL - as you say you will always be able to access the page by typing into the address what the rewritten URL would be ( domain.com/page.php?param1=1¶m2=2 etc ) and it will show the same page as domain.com/1/2. As long as you don't put any links anywhere in that format, no one will be any the wiser John