Forum Moderators: phranque
www.example.com/index.php/%year%/%postname%
Now that I moved my site, our pages do not need to have the "index.php" in it, so they look like this:
www.example.com/%year%/%postname%
The problem is that a number of our pages were linked on other websites, so people who click these links get an error. I followed directions on other threads to change my .htaccess file to look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [bingegamer.net...] [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
That fixed my website so that the homepage redirects, but I want ALL pages on the site to redirect, so that when someone clicks on a link that has the "index.php" in it, it takes that out.
Thanks for your help - I'm very new at this and it is probably an easy fix!
www.example.com/index.php/2008/some-page
it redirects them automatically to:
www.example.com/2008/some-page
I already got the homepage to work, using the code I posted above, but the rest of the site isn't working (and we have thousands of pages!)
The code is going into .htaccess, I think, unless there is another place it should go!
RewriteRule ^index\.php/([0-9]{4})/([a-z0-9-]+)$ http://www.domain.com/$1/$2 [R=301,L]
.
Assumptions:
$1 is always four digits long.
$2 can only contain letters, numbers, hyphens.
There is never a trailing slash at the end.
.
This would also work, but doesn't have to have just digits in $1, and matches absolutely anything for $2:
RewriteRule ^index\.php/([^/]+)/(.*) http://www.domain.com/$1/$2 [R=301,L]
The problem comes in that most people don't actually know what they want it to do.
As you can see, I made assumptions in both examples. You need to test with expected URLs and unexpected URLs, valid URLs and non-valid URLs, and make sure that all of them behave exactly how you want them to.