tags:

views:

30

answers:

3

i want to use somthing like http://www.example.com/domain.com instead of http://www.example.com/index.php?url=domain.com.

how can I do this using .htaccess?

update: i finally figured it out. :)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1

http://www.pagerankcheckertool.com/facebook.com

+3  A: 
RewriteEngine on
RewriteRule ^(.+)$ index.php?url=$1
ceejayoz
it's not getting the url.
giolicious
Then you've likely goofed something up in `index.php`.
ceejayoz
what do you mean?
giolicious
I mean that the code I gave you is quite simple and commonly used. Something's either wrong with your `index.php`, or your server isn't configured to allow `.htaccess` files or rewrite rules or something like that. Without more information, we can't help you much.
ceejayoz
A: 

check this out http://www.desiquintans.com/cleanurls

thedev
Answers like this become useless if the URL dies.
ceejayoz
it's not working
giolicious
+1  A: 

Depending on your needs, it may not be such a good idea to have everything rewritten as per your example, e.g. even a www.example.com/index.html would be rewritten to www.example.com/index.php?url=index.html so i'd recommend you use an initial sub folder or something in the url to seperate your rewritten urls from anything else.. i.e. www.example.com/urls/domain.com

To accomplish that you could setup a rewrite rule.. (assuming you have mod_rewrite active)

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^urls/(.+) /index.php?url=$1 [NC] 

that basically means any url that begins with urls/ and has one or more characters following.. the brackets around the .+ will 'group' that element and allow you use it again with the $1

Hope that solves what you want to accomplish!

Dave
my current url is like: http://www.example.com/index.php?url=domain.comi just want it to be like: http://www.example.com/domain.com
giolicious
then removing the 'urls/' bit from above should work just make sure you've got the other bits
Dave
It is possible to have a `RewriteRule` execute only if the requested URL is a 404 pre-rewrite, which would address this issue without changing the URL format.
ceejayoz
RewriteEngine onRewriteRule ^(.+)$ index.php?url=$1still not working?
giolicious
Not sure about the 404 I'm afraid. Still not having looking with the rewrite then?
Dave
Are you certain mod_rewrite is enabled? and you have Options +FollowSymLinks ?
Dave
yes i'm very sure
giolicious
Then as Ceejayoz says, maybe it is redirecting but something is happening in index.php. Do you have apache log entries you can share with us when you make a request?
Dave
I finally figured it out. :)
giolicious
What was it? for my curiositys sake ;-)
Dave
it's in my original post question. :)
giolicious