Need help with .httaccess and wamp
Posted by: FYIGeek (---.kellogg.id.cebridge.net)
Date: July 27, 2010 12:10AM

I am new i hope this is right place to post this.
I have the latest version of wamp server running and i am having an issue with my .httacces file.

Now i don't know if it the server or i am not making the code right maybe you guys can look it over?
I have a url to the members profiles like this:
./profile.php?action={$username} -link

and in the .httaccess file i have this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

ErrorDocument 404 /404.html
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^[(www]\.)?localhost/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ [localhost] [R,L]

RewriteRule ^accounts/{$username}/(.*)/$ profile.php?action={$username}

But it down work the url still prints out like:
localhost/profile.php?action=admin and not like localhost/accounts/admin/
So is it just not loading or did i do it wrong?

Any help would be great thanks!

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: toumimi (---.44.75-86.rev.gaoland.net)
Date: July 27, 2010 07:11AM

Rewriting syntax is : RewriteRule "what you receive" "what it means"

Example :
RewriteRule abc.html index.php

If you go to abc.html, it will output index.php, but keeping abc.html in url. It's a rewrited url.

Then, you can match some parts of the url, with regular expressions (and not variables !) :
RewriteRule abc-([a-z])+.html index.php?page=$1

So you have to learn regular expressions to match the right part and not evrything,
and have to generate new urls instead urls like "profile.php?..."
=> This what is behind, but should not be what is displayed in url.

Good luck smiling smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: FYIGeek (---.kellogg.id.cebridge.net)
Date: July 27, 2010 08:26PM

Wait i am a little lost here, maybe i am asking wrong i dont want a new html file loaded.
all i am trying to do is make it so if a user types: [localhost]
It will load the profile.php?action={$username} in the background .

Can i do this without another .html i don't use that old file type anymore my site is all php/.tpl.

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: c2dan (---.know.cable.virginmedia.com)
Date: July 27, 2010 08:38PM

The .html file does not actually exists, its a fake url. Which is what mod_rewrite is used for. toumimi's code is just an example

If your url is site.com/admin/username you'd use the following rewrite rule to call profile.php?action=username_here
RewriteRule admin/([a-z0-9_-]+)/? profile.php?action=$1

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: FYIGeek (---.kellogg.id.cebridge.net)
Date: July 27, 2010 09:15PM

Oh lol, that's what i was confused about thanks for helping me, the name it self changes that's why i have
it as {$username} but it still wont work even with the above example so i just dumped it and said F it let um see a nasty url idk lol

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: c2dan (---.know.cable.virginmedia.com)
Date: July 27, 2010 10:19PM

By they way when you use mod_rewrite you also need to recode your links to use the newer cleaner url, eg
<a href="admin/username">Username</a?

mod_rewrite wont recode the links for you.

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: toumimi (---.44.75-86.rev.gaoland.net)
Date: July 27, 2010 10:39PM

Yep.

If you want to associate a rewrited url (fake) to a real url (with file on your server and params in $_GET),
then you have to use example given by c2dan.

But you still can go to your old urls (profile.php) by typing it directly in browser.
It is still valid unless you tell Apache to forbid this url, or better, to redirect 301 to the new rewrited url.

To do so, you have to use a little hack, by adding a parameter when redirecting, to avoir infinite loop,
from new to old, old to new, etc.

You should use something like that to redirect old urls to new ones, so both are working.

RewriteCond %{QUERY_STRING} ^action=(.*)$
RewriteRule ^profile\.php$ /accounts/%1/? [R=301,L]

RewriteRule ^accounts/{$username}/ profile.php?action={$username}&rewriting [L]

If it's does not exactly fit your problem, you can play around this, because this one should work.

Don't forget to generate new urls or your website will contain only 301 redirections, which is really bad for loadings and referencement.

Good luck smiling smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: FYIGeek (---.kellogg.id.cebridge.net)
Date: July 29, 2010 02:13PM

Thanks for the help guys, i think it's working now but it keeps loading the 404 page "not found".
but when you click the link it does come out as accounts/username so i am getting closer.

i have tried it with the link as:
<a href="profile.php?action={$username}">{$username}</a>
and also
<a href="accounts/{$username}/">{$username}</a>

With the same result 404... So what am i missing now lol?
Is it caused from that 301 you mentioned. "redirect 301 to the new rewrited url." is fo re-direct how?



Edited 1 time(s). Last edit at 07/29/2010 02:20PM by FYIGeek.

Options: ReplyQuote
Re: Need help with .httaccess and wamp
Posted by: toumimi (---.44.75-86.rev.gaoland.net)
Date: July 29, 2010 09:00PM

Forget links that point to profile.php ! Redirection to your script is done by Apache (in .htaccess).

Use urls relative to the root of your website. To do so, start your url by a backslash.
<a href="/accounts/{$username}/">{$username}</a>

Difference with 301 is that it changes url in the browser => complete redirection
Without R=301, you just say this url loads this script, but it's all transparent for you users.
So no. The common problem is to have an infinite loop, which code below avoids.

You should check your links better, play with the .htaccess to match more urls (for testing), because if it is not catched by the .htacces, effectively, your url is invalid because folder account is not found.

Good luck smiling smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote


Sorry, only registered users may post in this forum.