mod_rewrite help please

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

mod_rewrite help please

Post by malcolmboston »

Im currently having some serious problems with mod_rewrite or maybe im just not understanding it right.....

Code: Select all

 
Rewriterule '^mens/item/(.*)/(.*)/(.*)/(.*) mens-item-(.*)-(.*)-(.*)-(.*).html [R=301, NC, L]
 
Ive added this line to my mod_rewrite file but i get an internal server error when its turned on.

basically i want this page:
http://www.redsquareclothing.co.uk/mens ... jma-Jacket
to automatically redirect using a 301 to this page:
http://www.redsquareclothing.co.uk/mens ... acket.html

Any help or nod in the right direction would be much appreciated.

edit: :? @ shortened URL

Regards, Mal
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: mod_rewrite help please

Post by onion2k »

I think you need to backslash the forward slashes, and the second part should be using references rather than .* ... eg

Code: Select all

Rewriterule '^mens\/item\/(.*)\/(.*)\/(.*)\/(.*)\/? mens-item-($1)-($2)-($3)-($4).html [R=301, NC, L]
The \/? at the end of the first part is just in case the user pops a / on the end of the URL.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: mod_rewrite help please

Post by malcolmboston »

Unfortunately that gives me an internal server error as well and i dont know anyway to get any error messages that can shed light on the error.

Just in case it helps, my full .htaccess file:

Code: Select all

 
ErrorDocument 404 http://www.redsquareclothing.co.uk/404.php
 
AddType x-mapp-php4 .php
RewriteEngine on
ReWriteBase /
RewriteRule ^mens/sale$ showSale.php [L]
RewriteRule ^mens/site-map$ sitemap.php [L]
RewriteRule ^mens/brands$ brandList.php [L]
 
RewriteRule ^mens/item/([0-9]+)/(.*)/(.*)$ showItem.php?stockCode=$1 [L]
RewriteRule ^mens/cat/([0-9]+)/(.*)/([0-9]+)/(.*)$ showCategories.php?catID=$1&page=$3&amount=$4 [L]
RewriteRule ^mens/brand/([0-9]+)/(.*)$ showBrand.php?brandID=$1 [L]
RewriteRule ^mens/brand_cat/([0-9]+)/(.*)/(.*)/(.*)$ showListings.php?brandID=$1&catID=$2 [L]
RewriteRule ^article/([0-9]+)/(.*)$ readArticle.php?id=$1 [L]
RewriteRule ^mens/sale/([0-9]+)/(.*)$ showSale.php?catID=$1 [L]
 
Options +FollowSymlinks
rewritecond %{http_host} ^redsquareclothing.co.uk [nc]
rewriterule ^(.*)$ http://www.redsquareclothing.co.uk/$1 [r=301,nc]
 
 
RewriteCond %{HTTP_HOST} ^(www.)?redsquareclothing.com
RewriteRule ^(.*) http://www.redsquareclothing.co.uk/$1 [R=301,L]
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: mod_rewrite help please

Post by onion2k »

Ah.. cut and paste error ... there's an apostrophe at the start of the rule that shouldn't be there.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: mod_rewrite help please

Post by malcolmboston »

same :banghead:

Code: Select all

 
ErrorDocument 404 http://www.redsquareclothing.co.uk/404.php
 
AddType x-mapp-php4 .php
RewriteEngine on
ReWriteBase /
RewriteRule ^mens/sale$ showSale.php [L]
RewriteRule ^mens/site-map$ sitemap.php [L]
RewriteRule ^mens/brands$ brandList.php [L]
 
RewriteRule ^mens/item/([0-9]+)/(.*)/(.*)$ showItem.php?stockCode=$1 [L]
RewriteRule ^mens/cat/([0-9]+)/(.*)/([0-9]+)/(.*)$ showCategories.php?catID=$1&page=$3&amount=$4 [L]
RewriteRule ^mens/brand/([0-9]+)/(.*)$ showBrand.php?brandID=$1 [L]
RewriteRule ^mens/brand_cat/([0-9]+)/(.*)/(.*)/(.*)$ showListings.php?brandID=$1&catID=$2 [L]
RewriteRule ^article/([0-9]+)/(.*)$ readArticle.php?id=$1 [L]
RewriteRule ^mens/sale/([0-9]+)/(.*)$ showSale.php?catID=$1 [L]
 
Options +FollowSymlinks
rewritecond %{http_host} ^redsquareclothing.co.uk [nc]
rewriterule ^(.*)$ http://www.redsquareclothing.co.uk/$1 [r=301,nc]
 
 
RewriteCond %{HTTP_HOST} ^(www.)?redsquareclothing.com
RewriteRule ^(.*) http://www.redsquareclothing.co.uk/$1 [R=301,L]
 
 
Rewriterule ^mens\/item\/(.*)\/(.*)\/(.*)\/(.*)\/? mens-item-($1)-($2)-($3)-($4).html [R=301, NC, L]
 
is there anyway to actually find the cause of the error?
Post Reply