Hi, I have a question about htaccess.

I have the following code:

RewriteRule ^([0-9a-zA-Z\-\_]+)$ ./profil.php?user=$1

This of course suports numbers, letters, capital letters, dash and underscore.

If I add a \. for it to support a dot, it gives me an error. How to add dot ?

Also, how to remove white space in links with htaccess ? I had a problem with someone that created a profile with space in his name. How to remove it or replace it with %2f or + or - or anything else ?

Thank you!

Recommended Answers

All 7 Replies

Try:

RewriteRule ^([0-9a-zA-Z.\-\_]+)$ ./profil.php?user=$1

But the rule seems ok to me, and you should use \. as you already tried. Which error gives you?

Concerning the spaces, you should prevent spaces at the moment of signup. You can add a field in the table for example url, where you remove/replace special characters and spaces:

id | username | password hash | url
-----------------------------------------
 1 | cip cip  | 2139Qdh9hn... | cip_cip

It gives me error from webhosting and the site does not show when I add the dot, can't seem why. I am using free hosting from 000webhost for this project.

Ok white space I have made it with str_replace in my php code, but how about supporting the dot ( . ) in htaccess ? Still not working...

for dot try below rule if it works.

RewriteRule ^([^_]*)$ ./profil.php?user=$1

Doesn't work for me either...

The weird thing is that I have another site on same hosting and when I add \. in htaccess works.

Maybe is the dot in front of profil? : ./profil.php?user=$1

Yes cereal, try this:
RewriteRule ^([^/]*)$ /profil.php?user=$1 [L]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.