helloworld001 Posted January 3, 2015 Share Posted January 3, 2015 Here is what I am trying to do. Get from this http://mysite.com/post.php?id=12&title=postname to this http://mysite.com/post/12/postname/ here’s the rewrite rule. Options +FollowSymLinks RewriteEngine On RewriteRule ^post/([a-zA-Z]+)/([0-9]+)/$ post.php?id=$1&title=$2 This is my html link that links to the post.php page. <a href="post.php?id=12&title=postname"> Click here to see the post! </a> It does not change the url. I have also tried it like below and it gives me an internal error. <a href="post/12/postname"> Click here to see the post! </a> Can you see what I have done wrong? Also if the above method for the linking is correct, how do I get the "id" and "title" using the $_GET? Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/ Share on other sites More sharing options...
requinix Posted January 3, 2015 Share Posted January 3, 2015 You have to change your own links so the second form is what you should use - not the post.php one. 1. The link should be absolute, so /post/12/postname (note the leading slash) 2. Your RewriteRule requires a trailing slash so either you remove that or you put the slash in your URLs If you still get an Internal Server Error, try Options +FollowSymLinks -MultiViews Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501605 Share on other sites More sharing options...
helloworld001 Posted January 3, 2015 Author Share Posted January 3, 2015 (edited) You have to change your own links so the second form is what you should use - not the post.php one. 1. The link should be absolute, so /post/12/postname (note the leading slash) 2. Your RewriteRule requires a trailing slash so either you remove that or you put the slash in your URLs If you still get an Internal Server Error, try Options +FollowSymLinks -MultiViews Here is the updated link with the added slash. <a href="/post/12/postname"> Click here to see the post! </a> The url does change now in the url field. It looks like this. http://localhost/post/12/postname, when it should look like this http://localhost/websitename/post/12/postname It does not give me the internal error but it gives me a different error. "The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error." Edited January 3, 2015 by helloworld001 Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501633 Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 Then you need to account for the "websitename". Best would be rebasing the site into that folder (ie, setting the DocumentRoot to be /path/to/websitename) or else you'll need to track that value somewhere and make sure you output it every time you generate URLs. Because you can't do relative paths (eg, just "post/12/postname") all the time: on the /websitename/post/12/postname page, trying that link again would take you to /websitename/post/12/post/12/postname. Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501643 Share on other sites More sharing options...
helloworld001 Posted January 4, 2015 Author Share Posted January 4, 2015 (edited) Then you need to account for the "websitename". Best would be rebasing the site into that folder (ie, setting the DocumentRoot to be /path/to/websitename) or else you'll need to track that value somewhere and make sure you output it every time you generate URLs. Because you can't do relative paths (eg, just "post/12/postname") all the time: on the /websitename/post/12/postname page, trying that link again would take you to /websitename/post/12/post/12/postname. Here is the new link. <a href="/websitename/post/12/postname"> Click here to see the post! </a> It appears as in the url and it gives an internal server error. http://localhost/websitename/post/12/postname. How do I set up the DocumentRoot path in the .htaccess? Edited January 4, 2015 by helloworld001 Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501655 Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 It appears as in the url and it gives an internal server error.Did you do that thing I said to do if you kept getting that error? How do I set up the DocumentRoot path in the .htaccess?Unless you want to support multiple sites at once, just put all the files you currently have in websitename/ in the parent directory (htdocs or /var/www or whatever that is). Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501675 Share on other sites More sharing options...
CroNiX Posted January 4, 2015 Share Posted January 4, 2015 If you do want multiple projects/sites on your dev box, create a virtual host and you don't need to muck around with that stuff. Each project should have one. Then the url could just be "www.yoursite.dev" or whatever you want the domain name to be on your dev server instead of "localhost/projectname". Then when you create absolute links like "/post/12/postname" it would be correct, like www.yoursite.dev/post/12/postname. You also wouldn't need to alter settings between the dev and live servers. Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501731 Share on other sites More sharing options...
helloworld001 Posted January 4, 2015 Author Share Posted January 4, 2015 If you do want multiple projects/sites on your dev box, create a virtual host and you don't need to muck around with that stuff. Each project should have one. Then the url could just be "www.yoursite.dev" or whatever you want the domain name to be on your dev server instead of "localhost/projectname". Then when you create absolute links like "/post/12/postname" it would be correct, like www.yoursite.dev/post/12/postname. You also wouldn't need to alter settings between the dev and live servers. Understood. I will try that. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/293612-quick-help-with-friendly-seo-url-rewrite/#findComment-1501753 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.