.htaccess - URL rewrites issues -


we having problem url rewrites on apache server using .htaccess.

goal: have following url stripped of category & subcategory while leaving generic redirect in place.

test 1:

redirect 301 /category/subcategory/product http://www.site.com/product

redirect works perfectly. single redirect desired page.

test 2:

redirectmatch 301 ^/category/subcategory/.*$ http://www.site.com/category/subcategory

redirect on own works urls desired.

the problem when have both urls in clean .htaccess file, , redirects in proper order (specific first, general), general redirect being used.

test 3:

redirect 301 /category/subcategory/product http://www.site.com/product

redirectmatch 301 ^/category/subcategory/.*$ http://www.site.com/category/subcategory

when visit www.site.com/category/subcategory/product, result www.site.com/category/subcategory/product, not desired result. instead, want url www.site.com/category/subcategory/product,

we have tried modified redirect to: redirect 301 /category/subcategory/product http://www.site.com/product [l] made no difference.

please help!

edit: added 3/25/2014

what trying provide specific redirects group of known products old product page new product page. trying add "catch all" redirect remaining unknown products category page.

here actual example redirect works:

redirect 301 /womens/western-dresses/stetson-cream-empire-waist-ls-western-dress http://www.site.com/stetson-cream-empire-waist-ls-western-dress

if above redirect added .htaccess file, works on own.

here second example redirect works:

redirectmatch 301 ^/womens/western-dresses/.*$ http://www.site.com/womens/western-dresses

the problem if have both of rules in .htaccess, in same order above, second rule triggered. try access www.site.com/womens/western-dresses/stetson-cream-empire-waist-ls-western-dress , result www.site.com/womens/western-dresses instead of desired result of www.site.com/stetson-cream-empire-waist-ls-western-dress

for clarity:

  • if remove .htaccess file, url 404s

  • if first rule listed, triggers perfectly

  • if second rule listed, second rule triggers perfectly

  • if both rules listed, second rule triggers.

  • we have deleted redirects .htaccess file. redirects below 2 lines. issue remains first redirect ignored. have tried changing start of first redirect ^/womens , ^womens change had no effect.

redirect 301 /womens/western-dresses/stetson-cream-empire-waist-ls-western-dress http://www.site.com/stetson-cream-empire-waist-ls-western-dress

redirectmatch 301 ^/womens/western-dresses/.*$ http://www.site.com/womens/western-dresses

your post little confusing, may misunderstanding trying do.

if memory serves, should not include leading slash in pattern when using these directives in .htaccess file. usage reserved httpd.conf. when these directives used in .htaccess file, leading path components have been stripped mod_access. guessing cause of troubles.

for example, should work (not tested):

redirect      301 ^category/subcategory/product http://www.site.com/product redirectmatch 301 ^category/subcategory/.*      http://www.site.com/category/subcategory 

as aside, [l] mod_rewrite lingo. "redirect" , "redirectmatch" part of mod_access.

edit 3/25:

redirect , redirectmatch can fussy when used in .htaccess files, particularly when dealing non-existent folders , mixed directives. can suggest move directly mod_rewrite? while has steep learning curve, never go once hang of it.

# assuming in .htaccess under documentroot: rewriteengine on rewriterule ^category/subcategory/product1\.html$ /product1.html [r=301,l] rewriterule ^category/subcategory/product2\.html$ /product2.html [r=301,l] rewriterule ^category/subcategory/.*              /category/subcategory [r=301,l] 

as aside, looks candidate rewritemap, although need declare map in httpd.conf.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -