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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.