apache - URL rewrite (routing), mod_rewrite, or PHP -
was trying sort out myself no luck.
i have website (php, apache), following structure, sample:
1. http://hostname/ 2. http://hostname/category?list=listname 3. http://hostname/product?id=...&name=productname 4. http://hostname/recipes 5. http://hostname/recipe?id=...&name=recipename + many others.
current .htaccess is:
rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename}\.php -f rewriterule ^(.*)$ $1.php
so examples http://hostname/category?list=... becomes /category.php?list... , catches php script , works.
i want make friendly urls these:
1. http://hostname/ 2. http://hostname/category/listname/ 3. http://hostname/product/productname/ 4. http://hostname/recipes/ 5. http://hostname/recipe/recipename/
and on other hand previous urls must still work webiste hugely indexed search enginges. oldstyle urls must 301 redirect new urls. ideas? efforts had errors. tried make php routing via index.php entry point, cant how deal oldstyle links.
first, disable multiviews
if enabled. try following rules enable 301 redrects new url structures:
rewriteengine on rewritecond %{the_request} ^get\ /(category|product|recipe)(?:\.php)?\?.*(name|list)=([^&\s]+) [nc] rewriterule ^ /%1/%3/? [r=301,l,nc]
as local/internal redirects actual pages, that'd have dealt individually:
rewriterule ^(category)/([^/]+)/?$ /$1.php?list=$2 [nc,l] rewriterule ^(recipe|product)/([^/]+)/?$ /$1.php?name=$2 [nc,l] rewriterule ^(recipe)/?$ /$1.php [nc,l]
Comments
Post a Comment