How to remove filename from URL

Hi!
I have following url.

http://localhost/ay/ads/category.php?cat=php%20category

I want url like following:

http://localhost/ay/ads/php-category/

How can I write rule and do other things in HTACCESS, so that above mentioned user friendly url can be made.

Thanks in advance

dd99,

Have you read the tutorial linked in my signature? That explains it all. Please read THEN ask questions of this sort.

Regards,

DK

dklynn!

I have read ‘Extensionless Links’ in your tutorial. As I have new to HTACCESS, I didn’t get full idea from it. Can you guide me little bit further to achieve this.

Thanks in advance

dd99,

First, what is the specification for your new links? In other words, how are they created (from a title extracted from a database?), from which characters (like only lowercase characters), is there anything else that would distinguish them from anything else in the ads directory (like category.php which has a dot character)?

Since your example uses a space in the cat’s value, you have some MAJOR problems to deal with - URIs with spaces in them are UGLY! %20 should be avoided at all cost! Even GET forms containing spaces convert them to +'s! Me, I prefer to use _'s as they don’t occur naturally in the language and are not easily confused with other characters (and I have PHP code to convert to/from _'s in my tutorial).

With that, YOU must create the new links to fit the above THEN you can use code like:

# htaccess in localhost's DocumentRoot

RewriteEngine on
RewriteRule ^/?ay/ads/([a-z_]+)/$ ay/ads/category.php?cat=$1 [L]

… which matches the ay/ads directory, captures only lowercase letters and _'s when trailed by ONLY a slash and redirects to category.php in the ay/ads directory with the query string cat={captured string}.

It’s just that easy - once you make a specification out of the new links that you’re using.

On one of my client’s sites, he does that exact thing but uses the title of his “blogs” which include several other characters so his ([a-z_]+) is actually ([-a-zA-Z_&'!]+) which matches -'s, lowercase and UPPERCASE letters, _'s, &‘s, apostrophes (’) and exclamation points. The + following the range definition is to say that one or more of the characters in the character range is required.

THAT should help you follow the tutorial … and get you on your way to using mod_rewrite with your website.

Regards,

DK

dklynn!
Thanks for guidance. I am using WAMP 2.0. I have enabled rewrite_module in Apache Modules.

I have found ‘apache2handler’ -> ‘Loaded Modules’ -> ‘mod_rewrite’ by running ‘phpinfo()’.

But when I test by running ‘http://localhost/ay/ads/test.html’. It shows me messsage of

‘This is the HTML file.’

After analysing httpd.conf of WAMP 2.0, I found following:
/*/
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>
/
/

But as per your recomendation:

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

This is the only difference I found there. What should I do with .htaccess, If I don’t want to disturb ‘httpd.conf’ file so that test given on your website should work properly on wamp.

Thanks in advance

dd99,

You MUST AllowOverride for mod_rewrite to work. If you don’t, it won’t.

Also, please remember that my test.html/test.php mod_rewrite code is designed to work in DocumentRoot, i.e., localhost/test.html (without the ay/ads directories - unless you updated my code for them).

Regards,

DK

Dk!
Really thanks for helping me out in running test files on WAMP. You are really GURU.

Thanaks once again for mentoring me in this problem.

dd99,

You’re very welcome! :Partier:

Regards,

DK