Results 1 to 5 of 5

Thread: url rewriting problem.

  1. #1
    Join Date
    May 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default url rewriting problem.

    I'm working on cake php and my url is

    http://<domainname>/registrations/user_list

    i want to display given url in address bar

    http://<domainname>/registrations/userslist.html

    then what i do.

    Please reply me and thanks in advance.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Which is the original URL and which is the "fake" URL? I think you want to add '.html'-- is that correct? Why? Most often url rewriting is used to avoid file extensions and simplify URLs.
    Alternatively you could set your server to parse .htm or .html as PHP. This is possible but takes extra resources. Then you could just use userslist.html with the PHP code and be done. Or do you need this for a lot of pages?

    There are two (or three) parts of URL rewriting:
    1. Use a rewriting engine (mod_rewrite in apache for example) to recognize a request URL and actually serve a different page. This is the "magic" part.
    2. Create that secondary (hidden) page and make it do what you want the displayed URL to do.
    3. Sometimes, you also need to forward extra information. For example /username could be converted to /showuser.php?user=username.

    Which part(s) above are you having trouble with?

    What system are you using to do this? Apache with mod_rewrite? Where's the code for that? Why is PHP related if you aren't sending variables?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes you are correct that i want to add .html in fake URL.

    Actually i'm using cakephp and in cake php the URL format is :
    http://<domainname>/registrations/user_list. So this is the original URL.

    But i want display a fake URL like
    http://<domainname>/registrations/userslist.html.

    You gave me two (or three) suggestions but i am confuse that how to use:
    1. how to use mod_rewrite in apache. (Are you talking about httpd.conf file or .htaccess?).
    2. How and where to create a secondary (hidden) page to display URL.

    Thanks for reply..

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    If this works in cake php, then I guess you should use that, but I don't know if anyone here can help you because not many of us (if any) use it.

    You could do either httpd.conf or .htaccess. .htaccess is a common method, though.

    Here's how URL rewriting works:
    The server receives a request for a certain URL. Then there is some code, somewhere, to override that and instead serve a new page. Let's say they request A.htm, but you have URL rewriting that says "instead of A.htm, show them B.htm". They still see the same URL in the address bar, but your server knows ("magically") to actually display a different page. Then this page (in the example, "B.htm") is shown instead. So basically it's like translating the URL and lying to the user about what page you're showing. It's useful, but also confusing.

    In your example, you will have the user type in the URL that you want to be shown, and you will need to find a way to go from that "pretty URL" to the actual underlying page. In other words, you'll have two URLs: 1) user-visible URL; 2) content URL (hidden, but actual location of your file). You will use url rewriting to display (2) instead of (1). So URL rewriting will need to recognize (1) and know to change that into (2).

    This is a conceptual explanation, and the way that I would do it is to use mod_rewrite in .htaccess. You can find lots of tutorials on google. It's more difficult if you want variables in the URL, but if you're just doing this for one page then it's as simple as listing the input URL and telling it to use another (internally) instead.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default

    Well, as mentioned, I guess you will have to use Apache's mod_rewrite.

    I just wanted to mention an unconventional and a rather new method of faking urls.

    Do you know about the HTML 5 history API? If your page executes this javascript on load :

    Code:
    history.pushState(null, null, 'userlist.html');
    It should rewrite the url of the browser, without reloading the page.

    But beware: This is a very new feature, and only higher versions of a very few browsers support it.

    I was just pointing out, how it could be done in the future

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •