Eccentric
06-10-2007, 09:19 PM
Think your links look ugly eg.
www.yoursite.com/index.php?page=test&skin=blue&language=eng&time=uk (http://www.yoursite.com/index.php?page=test&skin=blue&language=eng&time=uk)
Well .htaccess has made it alot easier for you to change this to something like;
www.yoursite.com/test/blue/eng/uk/ (http://www.yoursite.com/test/blue/eng/uk/)
What is .htaccess?
.htaccess (hypertext (http://en.wikipedia.org/wiki/Hypertext) access) is the default name of Apache's (http://en.wikipedia.org/wiki/Apache_HTTP_Server) directory (http://en.wikipedia.org/wiki/Directory_%28file_systems%29)-level configuration file (http://en.wikipedia.org/wiki/Configuration_file). It provides the ability to customize configuration for requests to the particular directory.
.htaccess files are commonly used for:
Authorization (http://en.wikipedia.org/wiki/Authorization), authentication (http://en.wikipedia.org/wiki/Authentication): .htaccess files are often used to specify the security restrictions for the particular directory, hence the filename "access". The .htaccess file is often accompanied by an .htpasswd file which stores valid usernames (http://en.wikipedia.org/wiki/Username) and their passwords (http://en.wikipedia.org/wiki/Password).
Customized error responses: Changing the page that is shown when a server-side error occurs, for example HTTP 404 Not Found (http://en.wikipedia.org/wiki/HTTP_404).
Rewriting URLs (http://en.wikipedia.org/wiki/Rewrite_engine): Various server-side PHP (http://en.wikipedia.org/wiki/PHP) scripts use .htaccess to rewrite "ugly" URLs to shorter and prettier ones.Taken from; http://en.wikipedia.org/wiki/Htaccess
Here's how you can do it.
So first of all we turn on and make sure all the links follow.
Options +FollowSymLinks
RewriteEngine OnNow this is where it gets hard, lets just test with one,
RewriteRule ^([A-Za-z0-9-]+)/$ index.php?page=$1 [L]this will change yoursite.com/index.php?page=test to yoursite.com/test/ (remember the last / ).
Now we will do the rest,
RewriteRule
^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ index.php?page=$1&skin=$2&language=$3&time=$4 [L]
You will need to save that in the appropriate directory.
Code breakdown,
([A-Za-z0-9-]+)This allows it to either be UPPERCASE lowercase or BoTh or numbers (0-9)
you can allow it just for numbers,
([0-9]+)
page=$1the $1 means that its the first in the url, like yoursite.com/first/second/third :) i think thats all enjoy.
OR you could use RichardKnox method which is also very good and easier to use thanks :),
You overcomplicated it.
http://www.yoursite.com/index.php?pa...ge=eng&time=uk
to
www.yoursite.com/test/blue/eng/uk/ (http://www.yoursite.com/test/blue/eng/uk/)
doesn't require as much as you;ve put. Try
Code:
RewriteEngine On
RewriteRule (.*)/(.*)/(.*)/(.*)/ index.php?page=$1&skin=$2&language=$3&time=$4
UPDATE:
Iv had a few PMs asking me how to access .htaccess so heres how:
Log into Cpanel and click on "File Manager". You should then get a pop-up asking which directory to open, if you look a bit further down on the pop-up you should see two Check boxs. Check "Show Hidden Files" and click "Go".
Now go to www if your not allredy in there, and you should see .htaccess :)
[ Credit to .:Jack120:. ]
Edited By Sunny. (Forum Moderator): Updated as requested.
www.yoursite.com/index.php?page=test&skin=blue&language=eng&time=uk (http://www.yoursite.com/index.php?page=test&skin=blue&language=eng&time=uk)
Well .htaccess has made it alot easier for you to change this to something like;
www.yoursite.com/test/blue/eng/uk/ (http://www.yoursite.com/test/blue/eng/uk/)
What is .htaccess?
.htaccess (hypertext (http://en.wikipedia.org/wiki/Hypertext) access) is the default name of Apache's (http://en.wikipedia.org/wiki/Apache_HTTP_Server) directory (http://en.wikipedia.org/wiki/Directory_%28file_systems%29)-level configuration file (http://en.wikipedia.org/wiki/Configuration_file). It provides the ability to customize configuration for requests to the particular directory.
.htaccess files are commonly used for:
Authorization (http://en.wikipedia.org/wiki/Authorization), authentication (http://en.wikipedia.org/wiki/Authentication): .htaccess files are often used to specify the security restrictions for the particular directory, hence the filename "access". The .htaccess file is often accompanied by an .htpasswd file which stores valid usernames (http://en.wikipedia.org/wiki/Username) and their passwords (http://en.wikipedia.org/wiki/Password).
Customized error responses: Changing the page that is shown when a server-side error occurs, for example HTTP 404 Not Found (http://en.wikipedia.org/wiki/HTTP_404).
Rewriting URLs (http://en.wikipedia.org/wiki/Rewrite_engine): Various server-side PHP (http://en.wikipedia.org/wiki/PHP) scripts use .htaccess to rewrite "ugly" URLs to shorter and prettier ones.Taken from; http://en.wikipedia.org/wiki/Htaccess
Here's how you can do it.
So first of all we turn on and make sure all the links follow.
Options +FollowSymLinks
RewriteEngine OnNow this is where it gets hard, lets just test with one,
RewriteRule ^([A-Za-z0-9-]+)/$ index.php?page=$1 [L]this will change yoursite.com/index.php?page=test to yoursite.com/test/ (remember the last / ).
Now we will do the rest,
RewriteRule
^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ index.php?page=$1&skin=$2&language=$3&time=$4 [L]
You will need to save that in the appropriate directory.
Code breakdown,
([A-Za-z0-9-]+)This allows it to either be UPPERCASE lowercase or BoTh or numbers (0-9)
you can allow it just for numbers,
([0-9]+)
page=$1the $1 means that its the first in the url, like yoursite.com/first/second/third :) i think thats all enjoy.
OR you could use RichardKnox method which is also very good and easier to use thanks :),
You overcomplicated it.
http://www.yoursite.com/index.php?pa...ge=eng&time=uk
to
www.yoursite.com/test/blue/eng/uk/ (http://www.yoursite.com/test/blue/eng/uk/)
doesn't require as much as you;ve put. Try
Code:
RewriteEngine On
RewriteRule (.*)/(.*)/(.*)/(.*)/ index.php?page=$1&skin=$2&language=$3&time=$4
UPDATE:
Iv had a few PMs asking me how to access .htaccess so heres how:
Log into Cpanel and click on "File Manager". You should then get a pop-up asking which directory to open, if you look a bit further down on the pop-up you should see two Check boxs. Check "Show Hidden Files" and click "Go".
Now go to www if your not allredy in there, and you should see .htaccess :)
[ Credit to .:Jack120:. ]
Edited By Sunny. (Forum Moderator): Updated as requested.