Web Analytics Made Easy -
StatCounter Can mod_rewrite be done in PHP? - CodingForum

Announcement

Collapse
No announcement yet.

Can mod_rewrite be done in PHP?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can mod_rewrite be done in PHP?

    I want to be able to make my URL's look neater but I don't want to muck around with Apache and change the mod_rewrite.

    Is there any way of doing this in PHP?

    If not, can PHP come up with links like:

    domain.com/section/topic/page

    Instead of:

    domain.com/section.php?topic=blah&page=blah2

    Thanks.

  • #2
    I'm not sure I understand what you mean by URLs looking "neater". Could you elaborate on that?

    Also, if:
    domain.com/section.php?topic=blah&page=blah2

    is supposed to be replaced by:
    domain.com/section/topic/page

    Do you not lose the values blah and blah2? How do you plan to incorporate them?

    If you're wanting to make your URLs neater in the sense that you don't have a bunch of parameters after the PHP file, then you may consider using POST instead of GET. GET will pass all the parameters from your form to the address bar as a URL, whereas POST will pass your parameters implicitly, and they will be available in the $_POST array.

    So to get blah, you would use $_POST["topic"].

    Hope that makes sense, hopefully someone else can assist you if need be.

    Good luck,
    Sadiq.

    Comment


    • #3
      you can use .htaccess files. Its very easy to do! take a look at http://www.codetricks.com/article.php?cat=&id=12
      PHP Weekly - A PHP Developers Resource
      PHP 5.1.4 and Ruby on Rails web hosting
      Moderator of PHP and Work offers and Requests
      Install Apache/PHP/MySQL
      (by marek_mar) | TinyPlugin Architecture

      Comment


      • #4
        That article looks about right. Thanks

        That's if I can persuade my host to let me have a look at the .htaccess

        Comment


        • #5
          nb - ForceType only works on Unix Apache, not Windows Apache.
          "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

          Comment


          • #6
            ForceType does work on win32 (at least on apache2/XP/2K)

            but if you are not allowed to modify your .htaccess file you can still use search-engine friendly URL's although they then end up looking like ..

            domain.com/section.php/var1/var2

            I then use the contents of $_SERVER['PATH_INFO'] to work out the passed data though $_SERVER['REQUEST_URI'] works just as well.

            beware relative links in your code when using such techniques !, e.g. in the page shown by the sample url above , './images/img.gif' will no longer be valid ... though '../../images/img.gif' will be , so use absolute paths where you can or design a prefix system for your relative links ..
            '<?=$DEPTH;?>images/img.gif';
            resistance is...

            MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

            Comment

            Working...
            X