sanjsimi Posted May 8, 2017 Share Posted May 8, 2017 Hi I am using this URL rewrite to make a user friendly URL but i have few problems with it. When i use URL like this http://localhost/blog/categoryname/title it works http://localhost/blog/category name/some title don't work http://localhost/blog/categoryname/some title don't work http://localhost/blog/category name/sometitle don't work http://localhost/blog/category don't work http://localhost/blog/category name don't work And my link need to be http://localhost/blog/category-name/post-title or http://localhost/categoryname/post-title and when i go to http://localhost/blog/category or http://localhost/blog/category-name to show me a results. RewriteEngine On RewriteRule ^blog/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ blog.php?category=$1&title=$2 [L] // this is just a test file to get url variables if (isset($_GET['category']) || isset($_GET['title'])) { echo "Category = " . $_GET['category'] . ", Title = " . $_GET['title']; } echo "<hr />"; var_dump($_GET); Now i want to know is .htaccess and this approach to make URL user friendly is faster then using a str_replace() function in PHP file to make this ? Or can somebody help me with this or give some tutorials, because i watched many of them and read on many forums and i see this is a complicated thing to do. I even used many htaccess generators but without any success. Is it problem in localhost because it don't have .com on end ? I really don't know what to do and how to make this work, sitting here 2 days and crashing my head Quote Link to comment Share on other sites More sharing options...
requinix Posted May 8, 2017 Share Posted May 8, 2017 I'm not sure what's up with that list but don't put spaces in friendly URLs. Your rewriting only handles the case with the category name and title. If you want to support just the category name then you have to add one for that too. RewriteRule ^blog/([a-zA-Z0-9]+)$ blog.php?category=$1 [L] Now i want to know is .htaccess and this approach to make URL user friendly is faster then using a str_replace() function in PHP file to make this ?Also not sure what you're saying here but the answer is probably yes. Quote Link to comment 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.