开发者

Htaccess PHP Redirecting. Unable to do so.. 404 not found error

开发者 https://www.devze.com 2022-12-18 18:28 出处:网络
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?).

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开发者_JAVA技巧 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


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}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号