Web Hosting Talk







View Full Version : I hate Rewrite... will someone just help ? ><


VolkNet
02-02-2005, 01:29 PM
I've been trying to get Mod_rewrite to work for about 8 hours now and am just fed up with it.

- I know mod_rewrite works because i can get it to redirect (i used an example on apaches manual and it worked.)

Can someone tell me what to put in my .htaccess file for the following case:

http://volknet.com/tempsys/template.php?cat=General (or whatever category)

should be transformed into

http://volknet.com/tempsys/template/General.html

(im not trying to advertise)

I have been putting the .htaccess file in the tempsys directory.

Thanks SOOOOO much if you can help. If you can relate to me on how frustrating it is to not get something to work... i could use your help.

VolkNet
02-02-2005, 01:41 PM
I currently am able to access the file, but when i go to

http://volknet.com/tempsys/template.php?cat=General it doesnt redirect me.

But if i manually type in http://volknet.com/tempsys/template.General.html (the format i wanted)

Then i can access that page!

What am i missing?

Here is my current .htaccess code:

-------start------------

RewriteEngine On
RewriteRule ^template.([a-zA-Z0-9]+)\.html$ template.php?cat=$1 [L]

--------------------end----------

VolkNet
02-02-2005, 04:04 PM
So How would i make all template.php?cat=category be permanently redirected to template.category.html (for any category)

Thanks

e-zone
02-02-2005, 04:13 PM
i think you will be better off with re-making "edit your current links" into the updated ones,
insteard of having it redirect each page to the new one.

if you dont care about "Seo" and all that, go ahead and make the redirect if someone got the code for you ;)

VolkNet
02-02-2005, 04:59 PM
Oh ok. Thanks that will work then too.

Burhan
02-03-2005, 02:01 AM
I don't think you quite understand mod_rewrite, because your rule doesn't make sense for what you are trying to do (if I understood your problem correctly)

First, you want this to happen:

template.php?cat=somecategory to redirect to template.somecategory.html

For this to work, you need to have a physical page for each category that you have in your system.

What I think you want is that

template.somecategory.html to redirect to
template.php?cat=somecategory, and the browser's address bar displays template.somecategory.html

For that to happen, you need the following rule:


RewriteEngine On
RewriteCondition ^template.(.*?).html$ template.php?cat=$1

VolkNet
02-03-2005, 03:26 PM
if i were to do this would the search engines see it as the static URL?

I think im just going to modify my program to work with the MOD_rewrite if the search engines will still see the URL as the dynamic one.

I really really appreciate the help.

Also fyrestrtr, would that be the only thing i needed in the htaccess file or would there be the line that i had above? Thanks.

VolkNet
02-03-2005, 06:32 PM
RewriteEngine On
RewriteRule ^(.*?).html$ template.php?cat=$1 [L]
RewriteRule ^(.*?).([0-9]+)\.html$ template.php?cat=$1&page=$2 [L]

How about this? All links will be pointed to the html files (i wont use a redirecting system)

Burhan
02-04-2005, 10:18 AM
That would work.

Greg Miller
02-06-2005, 08:32 AM
The question marks in the regular expressions aren't needed, since "*" means "zero or more"... You missed a backslash in the first rule to escape the dot, although this won't break your URLs.

Keep in mind that this will allow search engines to see two separate, duplicate pages if any of them find or have already found the .php URL.

If you end up with inbound links to both URLs, the PR will be split between the two instead of being combined, and one of the pages (hard to say which, and it may vary from one SE to the next) will get buried as a duplicate. Most likely, the SEs will view the new URL (the .html one) as a duplicate and show only the .php page in their results.

Burhan
02-06-2005, 11:08 AM
The ? makes the expression "un-greedy", but you made some good points regarding PR/SE.