0

I am working on a ask answer website and thanks to Alex, I got the permalinks I wanted to have on the website (PHP Permalinks.. how to change?).

Here is the format..

Original: domainname.com/cat/how-are-you-|162

New permalinks: domainname.com/cat/how-are-you-|162.html

The new permalinks won't work i.e, it doesn't load the page and displays 404 Not found error. My knowledge of rewriterules are very basics, I did try some functions but to my dismay, they didn't work at all.

How do I redirect original to the new permalinks using htaccess file?

Thank you.

Edit1: @Ignacio - Currently, I haven't implemented it on the server as I don't want to lose traffic, but I can do it once again tonite and will update with the result.

@Pekka - Here is the .htaccess file http://pastebin.com/m23c7d2b6

Community
  • 1
  • 1
regguy
  • 34
  • 4
  • What file do your logs claim the web server is trying to access? – Ignacio Vazquez-Abrams Jan 27 '10 at 12:49
  • And can you show the htaccess file you're using? – Pekka Jan 27 '10 at 12:49
  • Updated my question and added the htaccess file.. Thanks! – regguy Jan 27 '10 at 13:03
  • I answered your question below, but I think the real answer is: **DON'T DO THIS!** Why would you possibly add a *file extension* to your *URLs*? – Jeremy Stein Jan 27 '10 at 17:45
  • Thanks Jeremy, without an extension the permalinks are broken as it uses pipeline and id numbers. I assume this will make it search friendly? – regguy Jan 27 '10 at 17:55
  • Broken how? You're still using pipes and IDs. Permalinks across the web work just fine without file extensions. Perhaps what you want is to replace the pipe with a slash? – Jeremy Stein Jan 27 '10 at 18:07
  • I am done playing with .html extensio n can't seem to make it work with htaccess.. how can I strip those slashes and question marks from the url? That's the only option I have got now.. thanks! – regguy Jan 27 '10 at 19:21
  • Your question doesn't make sense. You want to strip slashes from the url? So something like `http:stackoverflow.comquestions`? Try rephrasing and expanding your question with an example and post it as a new question. – Jeremy Stein Jan 28 '10 at 19:20

1 Answers1

0

You want to do two things:

  1. Permanently redirect old permalinks to new permalinks and
  2. Make new permalinks work.

To redirect the old permalinks, add something like this:

RewriteCond %{REQUEST_FILENAME} !.*\.html$
RewriteRule ^(.+/.+)$ $1.html [L,R=301]

To get the new permalinks to work, change this line:

RewriteRule ^([^/.]+)/([^/.]*)?$ view.php?title=$1&id=$2&%{QUERY_STRING}

to this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/([^/.]*)\.html?$ view.php?title=$1&id=$2&%{QUERY_STRING}
Jeremy Stein
  • 19,171
  • 16
  • 68
  • 83
  • Thanks Jeremy, I did make the changes but they didn't work primarily because .html extension was assigned in the core files and it was done with the help of Alex (member of this community) in the file index.tpl. Right now, the css is stripped from the website for no particular reason. I would appreciate if you can check out this thread http://stackoverflow.com/questions/2127913/php-permalinks-how-to-change and the website is http://studentask.com – regguy Jan 27 '10 at 18:02