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


No announcement yet.

Can mod_rewrite be done in PHP?

  • 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:


    Instead of:



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

    Also, if:

    is supposed to be replaced by:

    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,


    • #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


      • #4
        That article looks about right. Thanks

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


        • #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


          • #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 ..


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