- This topic is empty.
-
AuthorPosts
-
June 25, 2009 at 2:47 pm #25256
mattvot
MemberSimilar to WordPress permalinks. Does anybody know how to make a .htaccess file that imitates an url.
An example is a site I am building. Pages are selected by going to http://www.doamin.com/d/?p=about
When users go to http://www.doamin.com/d/about/ I would like the browser to read http://www.doamin.com/d/about/ but use http://www.doamin.com/d/?p=about
I know this can be done, but have absolutely no idea how to combine .htaccess with php.
I have googled to no avail. I can’t think of any good keywords to use, nothing to describe the issue here.
June 25, 2009 at 3:08 pm #59703apostrophe
ParticipantI just searched "htaccess pretty urls" and came up with a whole bunch of results. Here’s a nice one that seems to make sense even to me with my rudimentary knowledge of PHP.
June 25, 2009 at 3:56 pm #59695mattvot
Memberthanks, I looked at alot of the links using ur search suggestion, but is it me or are there tuts just far too confusing.
Well they are to me :cry:
If somebody could just explain in simple terms I would be very greatfull
June 25, 2009 at 4:02 pm #59697apostrophe
ParticipantSorry, I forgot to include the link. :oops:
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.htmlJune 25, 2009 at 5:29 pm #59714davesgonebananas
MemberIt is a confusing subject because it involves two of the great mysteries of the intarwebz. Apache .htaccess files and regular expressions.
There is no way around it. Regular expressions are hard. I found them hard when I first encountered them, and I sometimes still use a cheatsheet when creating them. But don’t let that put you off. Learn them. Regular expressions are found not just in .htaccess, they are all over the place – PHP, Perl, Shell scripts, Ruby on Rails, Javascript, Super Deluxe Automatic Coffee Makers. Alright, maybe not that last one but they are pretty much everywhere else and that makes them worth learning!
Apostrophe posted a good link about .htaccess so I will post one about regular expressions in general – http://www.regular-expressions.info/
June 25, 2009 at 6:00 pm #59719mattvot
Membercool I’ve heard of RE before but didn’t look to much into it. i’m getting confused. I’ve tried this but it doesn’t work, any ideas?
Code:RewriteEngine on
RewriteRule ^d/([a-z]*)/$ /d/index.php?p=$1June 26, 2009 at 4:46 pm #59779freekrai
ParticipantIn the d/ folder, add this:
Code:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?p=$1 [L]June 27, 2009 at 8:36 am #59811mattvot
MemberThanks, that worked, to a certain extent.
It delivers the page. But the stylesheet won’t link, and the includes() function doesn’t work.
June 29, 2009 at 8:50 am #59862Argeaux
Participantput a slash for every stylesheet, img and include. It should work then.
Code:“includes/stylesheet.css”“/includes/stylesheet.css”
June 29, 2009 at 11:40 am #59870Mr KiTT3N
MemberI recommend anyone that wants to achieve clean urls and is starting a site from scratch should look at using a MVC/MTV framework
CodeIgniter, cakePHP, Zend Framework ect…
Keep in-mind the way they handle the rewrite rule breaks the way most people are accustomed to building web sites….
Traditionally sites follow a folder structure
Example:Code:http://example.com/home/index.php
folder “home” -> file “index.php”The Rewrite will instead of looking in that folder for that file it treats everything a variable
Rewrites to http://example.com/index.php
Then index.php takes "home/index" as a variable and delivers content accordingly
(Controller = ‘home’, Action = ‘index’)In addition, this will allow you to define custom uri structures like
Code:$customURI = ‘profile/:userName’;This will point to the profile controller and give a username variable equal to benjamin allowing you to pull up content about a unique person
Anyways, take a look at it, alot of sites use frameworks like such and for good reason too, very powerful, extensive useful libs and faster development of your sites
June 29, 2009 at 3:34 pm #59887mattvot
Memberthanks for the advice, but I want a light site with all my own coding. I need to learn how to do it all myself to improve my skills, no offense. But yeh, beginners or anyone for that matter could use frameworks to make the job easier.
January 19, 2010 at 7:31 pm #69658MesmerLab
MemberI’m currently learning CodeIgniter and am having problems with the .htaccess regex part.
From their wiki, I’m using the following RewriteRule:
Code:RewriteRule ^(.*)$ index.php?/$1 [L]Yet it does not work.
works http://60dayflip.com/index.php/site/dosomething
doesn’t http://60dayflip.com/site/dosomething
doesn’t http://60dayflip.com/dosomethingAny clues?
January 19, 2010 at 8:13 pm #69659mattvot
MemberGo to the config.php file and change
Code:$config[‘index_page’] = “index.php”;to
Code:$config[‘index_page’] = “”;January 21, 2010 at 3:45 am #69735MesmerLab
MemberYep, that’s the first thing I did.
April 17, 2013 at 11:09 pm #132241grome
Memberi think u must add base url in front of your function location and image location.
Example : you put css like this …href=”css/main-style.css”
it should be like this …href=”http://www.yourdomain.com/css/main-style.css”
correct me if i’m wrong :)
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.