php - Redirecting from one page to another page on my website causes 404 error after using .htaccess file
Currently I'm working on a php blog.Where I have used .htaccess file to get clean url,here is the code.
RewriteEngine On
RewriteCond %{HTTPS} !=off
RewriteCond %{HTTP_HOST} ^mywebsitename\.com$
RewriteRule (.*) http://www.mywebsitename.com/$1 [R=301,L]
RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)?$ post.php?post_id=$1&title=$2 [L]
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images)/(.*)$ $2/$3 [L]
I got this code online.As I'm new to php and this htaccess thing,that's why I don't have much idea about it.
URL Before adding .htaccess file was: [http://www.mywebsitename.com/post.php?post_id=12&title=post-title][1]
And,URL after adding .htaccess file: http://www.mywebsitename.com/12/post-title
So rewriterule gave me the url that I want.But it has cause error in redirection of the page.Before using .htaccess file whenever i clicked on home button after visiting following url: http://www.mywebsitename.com/post.php?post_id=12&title=post-title then URL redirected successfully to home page,that is:http://www.mywebsite.com/index.php page.
But now after using .htaccess file after visiting the same url it is redirecting like this: http://www/mywebsitename.com/12/index.php
And now it is firing 404 page not found error.Because technically there is no such page present under 12 directory on server.
So after visiting the following link:http://www.mywebsitename.com/12/post-title I want it to redirect properly as it was redirecting the pages before adding the .htaccess file.
Please guys help me out. Thanks in advance.
Answer
Solution:
Is the link http://www.mywebsitename.com/12/post-title your actual url. Is mywebsitename the your domain name? I think you should replace it with the actual domain name. It might just be a placeholder text