Forum Moderators: phranque

Message Too Old, No Replies

Newbie try to rewrite with .htaccess

Rewrite dynamic and static pages on the same .htaccess

         

gjfortin

2:44 am on Jun 1, 2009 (gmt 0)

10+ Year Member



Hi,

I need to rewrite urls. Some are dynamic and others are static.

I write an .htacess file and I upload this file in the concert folder. But nothing works.

I would like to change dynamic urls like this one:
http://www.example.com/00_AN/03_Catalogue/catalogue_technical.php?ItemSelect=6
redirect to:
http://www.example.com/00_AN/03_Catalogue/product.php

and static pages like:
http://www.example.com/00_AN/03_Catalogue/catalogue_technical_old_product.html
redirect to:
http://www.example.com/00_AN/03_Catalogue/new-product.php

.htaccess file is stored in /03_Catalogue/

Here are the rules that I write:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^ItemSelect=6$
RewriteRule ^/catalogue_technical.php$ http://www.example.com/00_AN/03_Catalogue/product.php? [L,R=301]

RewriteCond %{QUERY_STRING} ^ItemSelect=12$
RewriteRule ^/catalogue_technical.php$ http://www.example.com/00_AN/03_Catalogue/new-product.php? [L,R=301]

redirect 301 /catalogue_technical.html http://www.example.com/00_AN/03_Catalogue/catalogue.php

redirect 301 /catalogue_technical-item.html http://www.example.com/00_AN/03_Catalogue/item.php

Nothing works. I do not know if I can write an .htaccess file with dynamic and static pages in the same file.

I have to keep this ugly folder architecture because pages in it have a good PR to keep

Are you able to tell me what I am doing wrong?

Thank You

jdMorgan

1:53 pm on Jun 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Nothing works.

That's rather ambiguous, and doesn't tell us much...

Does this simple test rule work?


Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^foo\.html$ http://www.google.com/ [R=301,L]

Note: No leading slash on RewriteRule pattern if code is in .htaccess or a <Directory> container in httpd.conf or other server config file. In these cases, the requested URL-path is 'localized' to the directory, and the leading path info will not be present in the URL-path examined by RewriteRule.

> I do not know if I can write an .htaccess file with dynamic and static pages in the same file.

Yes you can, assuming that mod_alias and mod_rewrite are allowed on your server.

> I have to keep this ugly folder architecture because pages in it have a good PR to keep.

To be precise, you may *want* to keep the URL-structure to preserve PR, but you do not have to keep the file-folder structure. You can use mod_rewrite to 'connect' the old URLs to new file locations if you wish. Also, a properly-implemented 301 redirect will pass PR, but it may takes some time --days to months-- for search engines to pass the PR/link-popularity from the old URL to the new. This time delay depends on how frequently your pages are spidered.

Do not mix mod_alias and mod_rewrite directives in the same .htaccess file. Doing so means that you cannot control the order of execution of these directives, since directives are processed on a per-module basis, and module execution order is not controlled by your code order. This module execution order may change if you change hosts or upgrade your server. Therefore, I recommend that if you use mod_rewrite for any redirects or rewrites, that you use it for all redirects as well.

Jim

gjfortin

6:26 pm on Jun 7, 2009 (gmt 0)

10+ Year Member



Hi Jim,

the test:
Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^foo\.html$ [google.com...] [R=301,L]

does not works.

jdMorgan

9:06 pm on Jun 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then it is likely that you cannot use mod_rewrite... :(

Contact your host and ask them. If they cannot support your needs, you will need to find a hosting company that can.

Jim