htaccess redirect (301) all my old content from my WordPress to my new URL design. I want to redirect all the last trailing slashes to .html ... the permalinks are already working, but I don't want to lose all my collected backlinks for which I worked so hard.
This is how my URLs look like:
- Pages (old):
/pages/redirection/
should redirect to/pages/redirection.html
- Posts (old):
/new-permalink/
should redirect to/news/new-permalink.html
- Custom Posts
/permalink/
should redirect to/projects/permalink.html
The following rewrite rule does not work for me. It ignores my rewritebase, so it redirects /projects/permalink/
to /permalink.html
not to /projects/permalink.html
.
RewriteEngine On
Options +FollowSymLinks
RewriteBase /project/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project/index.php [L]
RewriteRule /project/([^/]*)/?$ /project/$1.html [L]
/projects/
folder already, then remove/project/
from rewrite pattern for last rule; should beRewriteRule ([^/]*)/?$ /project/$1.html [L]
. P.S. and please stop using xxxxx for everything -- be creative and use a bit more realistic/easy to distinguish URLs...example.com/project/
.. then you may have such response. If so -- addRewriteRule ^$ /project/index.php [L]
line after RewriteBase line, for example (but definitely before the previously mentioned rule).<IfModule mod_rewrite.c> RewriteEngine On Options +FollowSymLinks RewriteBase /project/ RewriteRule ^$ /project/index.php [L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /project/index.php [L] RewriteRule ([^/]*)/?$ /project/$1.html [L] </IfModule> # END WordPress
RewriteLogLevel 9
and check rewrite log for details. You are the person who knows for sure how site works/should work, and should see from logs what is going wrong and where. All my advices, while technically be correct, still may be inappropriate for particular situation/location.