Jump to content

.htaccess URL don't display properly


sanjsimi

Recommended Posts

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

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 :(

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.