.htaccess – How do you do this? http://www.example.com/domain.com – Education Career Blog

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



RewriteEngine on
RewriteRule ^(.+)$ index.php?url=$1


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!

Leave a Comment