If you go to a url like the following: http://stackoverflow.com/questions/9155602/
the address bar will be updated to http://stackoverflow.com/questions/9155602/redirect-existing-file-to-different-url-using-mod-rewrite
. This is not done with JavaScript and not with a hard-refresh, my best guess is that it's done with mod_rewrite; however, how would it know the title of the article without server side processing with php?
I just updated my site to use SEO friendly url's, it used to be /shows.php?id=review-1
and now it's /review/1/super-baseball-2020
. The text at the end doesn't actually really matter when it comes to my rewrite which is:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)/([0-9]+)/([a-z0-9-]+)?/?$ /shows.php?id=$1-$2 [L,NC]
My current path of making sure Google doesn't hit me for duplicate content, and that bookmarks get forwarded properly is the following:
RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-1(?:&|$) [NC]
RewriteRule ^ /review/1/super-baseball-2020/? [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-2(?:&|$) [NC]
RewriteRule ^ /review/2/aero-fighters-2/? [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=review-3(?:&|$) [NC]
RewriteRule ^ /review/3/aero-fighters-3/? [R=301,L,NC]
.... and so on ....
That solution is very shortsighted and is thousands of lines to put into my .htaccess.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…