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] 
  • If you are in /projects/ folder already, then remove /project/ from rewrite pattern for last rule; should be RewriteRule ([^/]*)/?$ /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...
    – LazyOne
    Jul 26, 2011 at 20:42
  • Ok, next time i try beeing more creative ;) ...now it returns on domain.com/project/ ...You don't have permission to access /project/.html on this server.
    – Gecko453
    Jul 26, 2011 at 21:34
  • Which URL you were accessing? if example.com/project/ .. then you may have such response. If so -- add RewriteRule ^$ /project/index.php [L] line after RewriteBase line, for example (but definitely before the previously mentioned rule).
    – LazyOne
    Jul 26, 2011 at 21:38
  • doesnt work for me.. now it looks like this <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
    – Gecko453
    Jul 26, 2011 at 21:52
  • TBH Now I'm lost on what is working, what is not (and why) and how it supposed to work. Without knowing you project details I will constrain myself from making more "wild" guesses. I can only recommend enabling rewrite debugging (if you can edit server/virtual host config) -- 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.
    – LazyOne
    Jul 26, 2011 at 23:40

1 Answer 1

RewriteRule ^pages/([^/]*)/?$ pages/$1.html

Should do the trick.

  • thx, but plz see my editted question :)
    – Gecko453
    Jul 26, 2011 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.