Reputation: 35
so I was wondering if something like this is at all possible.
I was hoping to change /?directory=$variable
to something like /$variable
An actual example might be easier to understand. So I want <a href='/{$variable}' >
to really be /?directory=$variable
or in url rewite terms i guess /?page=$1
I hope this makes sense. I am really no good with rewriting. Is this even possible? I was hoping to exclude index.php on that. however if that cannot be done, and example with index.php?ect.. will work. Thanks!
Upvotes: 1
Views: 110
Reputation: 48131
Yes it's possibile if your server/hosting supports it you can do it by creating an .htaccess
file with:
RewriteEngine On
RewriteRule ^/(.+)$ /?directory=$1 [L]
If you want to allow other directories/files to get accessed normally you should do something like:
RewriteRule ^/([a-z]+)$ /?directory=$1 [L]
This will capture any subdirectory like /abc
but not /css.css
or /customsub/other file
Welcome to the world of SEO optimizer lol.
Upvotes: 1
Reputation: 1
Read this: http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
Upvotes: 0
Reputation: 46620
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php?directory=$1 [NC,L]
Upvotes: 0
Reputation: 26
URL Rewriting is done on the Web Server (Apache, IIS, etc.) and not within a scripting language like PHP.
If you are using Apache, check this out:
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Upvotes: 0