Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End .htaccess custom url with php

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #25256
    mattvot
    Member

    Similar 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.

    #59703
    apostrophe
    Participant

    I 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.

    #59695
    mattvot
    Member

    thanks, 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

    #59697
    apostrophe
    Participant

    Sorry, I forgot to include the link. :oops:
    http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

    #59714

    It 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/

    #59719
    mattvot
    Member

    cool 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=$1
    #59779
    freekrai
    Participant

    In the d/ folder, add this:

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) index.php?p=$1 [L]
    #59811
    mattvot
    Member

    Thanks, that worked, to a certain extent.

    It delivers the page. But the stylesheet won’t link, and the includes() function doesn’t work.

    #59862
    Argeaux
    Participant

    put a slash for every stylesheet, img and include. It should work then.

    Code:
    “includes/stylesheet.css”

    “/includes/stylesheet.css”

    #59870
    Mr KiTT3N
    Member

    I 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

    http://example.com/home/index

    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’;

    http://example.com/profile/benjamin

    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

    #59887
    mattvot
    Member

    thanks 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.

    #69658
    MesmerLab
    Member

    I’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/dosomething

    Any clues?

    #69659
    mattvot
    Member

    Go to the config.php file and change

    Code:
    $config[‘index_page’] = “index.php”;

    to

    Code:
    $config[‘index_page’] = “”;
    #69735
    MesmerLab
    Member

    Yep, that’s the first thing I did.

    #132241
    grome
    Member

    i 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 :)

Viewing 15 posts - 1 through 15 (of 15 total)
  • The forum ‘Back End’ is closed to new topics and replies.