Forum Moderators: phranque

Message Too Old, No Replies

Need urgent help with htaccess.

htacces mod rewrite issues

         

chinedu

7:54 pm on Dec 8, 2004 (gmt 0)

10+ Year Member



I've been trying to learn this htaccess thing but I am not successful. This is what I'm trying to do:

Here is a sample link:

/mls/city.php?realtor=Kuna&state=Idaho

I want the bots and users to see as: /realtor/Idaho/Kuna.htm

So basically: /realtor/state/city.htm

One more thing... When I link to this page would i link to it as:

/mls/city.php?realtor=Kuna&state=Idaho

or

/realtor/Idaho/Kuna.htm

Can someone please tell me the htaccess script for this... I really appreciate your help!

jdMorgan

8:20 pm on Dec 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chinedu,

Welcome to WebmasterWorld!

Here are the steps you need to take:

  • Modify your php script to output links like "/realtor/Idaho/Kuna.htm"
  • Add mod_rewrite code to detect those URLs, and change them back to "/mls/city.php?realtor=Kuna&state=Idaho" in order to call your script.

    mod_rewrite works at the front end of Apache request processing, after a request is received and before any content is served or any scripts are run. Therefore, it can change only incoming URLs, and cannot change the URLs output on your pages as links. So, the above procedure is what you need to do to make it work.

    There are plenty of threads about this method here in the forum, including several recent ones. See also our charter for references to documentation.

    I hope this helps get you started,
    Jim

  • chinedu

    8:35 pm on Dec 8, 2004 (gmt 0)

    10+ Year Member



    Thanks,

    the thing is that I can't figure out how to write the mod_rewrite.

    jdMorgan

    8:43 pm on Dec 8, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Again, try a search [google.com] for many examples, and please see our forum charter [webmasterworld.com] for references and for information about our policies.

    Jim

    chinedu

    8:48 pm on Dec 8, 2004 (gmt 0)

    10+ Year Member



    Ok... I tried this:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule mls/(.*)-(.*)\.htm$ /mls/city.php?state=$1&realtor=$2

    But I'm getting a 500 Internal Server Erro when I go to /mls/Idaho-Kuna.htm

    jdMorgan

    9:02 pm on Dec 8, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Code looks OK, but it could be much more efficient:

    RewriteRule ^mls/([^-]+)-([^.]+)\.htm$ /mls/city.php?state=$1&realtor=$2 [L]

    What you had should have worked, though. Check your server error log to see what the problem was. I assume we don't even know if mod_rewrite is configured on your server at this point.

    Jim

    chinedu

    9:09 pm on Dec 8, 2004 (gmt 0)

    10+ Year Member



    Yeah... I think you maybe right about the configuration. I'm trying to figure out how to view my server error log right now.

    chinedu

    9:22 pm on Dec 8, 2004 (gmt 0)

    10+ Year Member



    Yeah... I'm using Netfirms advanced hosting but they don't have a error log link in the cpanel for me to view. Is there no solution for me? I really appreciate your help jmorgan.

    jdMorgan

    10:15 pm on Dec 8, 2004 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Well, if you haven't used mod_rewrite before on this server, try a very simple rewrite, like

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^mamahoohoo\.htm$ /mls/city.php?state=Idaho&realtor=Kuna [L]

    Then request /mamahoohoo.html with your browser and see if you get the right php page.

    If that doesn't work, then it's likely you can't use mod_rewrite on that server without a config change.

    On many hosting accounts, the error logs are saved in the same subdirectory as your stats, so try looking in there via FTP.

    Jim

    chinedu

    10:32 pm on Dec 8, 2004 (gmt 0)

    10+ Year Member



    Thanks for your help.

    I knew I wasn't this stupid (lol)... I've been going at this the last 24 hours. I wrote them and they don't offer mod_rewrite on their servers right now. I may be looking for new hosting here soon!