...

View Full Version : .htaccess mod_rewrite issues



Terminator3d
08-26-2006, 01:13 PM
Hi guys im new here so please be nice :)

Ok im having some problems with understanding how htaccess files work with php. Ive written a site in php which uses dynamic content so I want to rewrite the querystrings.

As it stands within the php code ive written it so the URLs are outputted with the format:
http://www.mysite.com/view.php?tn=all&order=1&page=1

And im after something like:
http://www.mysite.com/view/all/1/1

Do I need to modify the format I output these URLs within the php....or does the htaccess file do everything?

As it stands ive got:

Options +FollowSymLinks
RewriteEngine on
RewriteRule view/(.*)/(.*)/(.*)/$ view.php?tn=$1&order=$2&page=$3

Can anyone help me out with this please? Ive been trying to get this working a while and arent sure what im doing wrong. Everything I try either doesnt work or gets a server error.

Thanks in advance.

Anthony2oo4
08-26-2006, 02:16 PM
try:

Options +FollowSymLinks
RewriteEngine on
RewriteRule view/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ /view.php?$1=$2&$3=$4&$5=$6

will output

http://www.mysite.com/view/tn/all/order/1/page/1/

Got this from

http://www.webmaster-toolkit.com/mod_rewrite-rewriterule-generator.shtml

but you can try editing it.

If you want it the way you stated I think you can use this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule view/(.*)/(.*)/(.*)/$ /view.php?tn=$1&order=$2&page=$3

which means your links will be:

http://www.mysite.com/view/all/1/1

i think :)

Terminator3d
08-26-2006, 02:37 PM
Thanks for the help but I think it may have something to do with my php opposed to the htaccess....obviously im a newbie to this so stop me if im wrong.

Say for example I create a hyperlink and echo out the querystring like below, will the htaccess rewriting of querystrings work?

<a href="<?php echo "view_values.php?tn=all&amp;order=$order&amp;page=1"; ?>">All</a>

I cant work out where Im going wrong at all. Any help appreciated greatly....its driving me crazy. Im told the server has been configured for htaccess and mod_rewrite so dont think the problem lies there.

Thanks.

Anthony2oo4
08-26-2006, 02:42 PM
ah sorry i didnt read your post properly, no im pretty sure that you hae to create the links yourself in php. Before you mess everything up id suggest you make it a chooseable option via mysql si you can do:

$usemodrewrite = "yes";
if ($usemodrewrite == "yes") {

$link = "http://www.mysite.com/view/tn/all/order/1/page/1/";

} else {

$link = "http://www.mysite.com/view.php?tn=all&order=1&page=1";

}

Terminator3d
08-26-2006, 08:16 PM
This is just too much fun. Ive now altered the links into a format like:
http://www.mysite.com/view_value/all/1/1

Now Im getting the following 404 error:

The requested URL /view_value/all/1/1 was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

My htaccess file looks like:

Options +FollowSymLinks
RewriteEngine on
RewriteRule view_value/(.*)/(.*)/(.*)/$ /view_value.php?tn=$1&order=$2&page=$3

Any ideas where im going wrong at all?

Thanks

Terminator3d
08-26-2006, 11:19 PM
Thanks for the help Anthony Ive solved it now.

:thumbsup:

Anthony2oo4
08-27-2006, 12:41 PM
can you post what it was ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum