Forum Moderators: phranque
site.org/articles/33 => site.org/view.php?id=33
So I tried
RewriteEngine on
Options FollowSymLinks MultiViews ExecCGI
RewriteRule ^articles/([[:digits:]]+)$ view.php?id=$1 [NC]
but this confuses the browser. The redirect works (as in I get to view.php which has the $_GET argument), but the browser now looks for paths beginning site.org/articles, and so it cannot find the CSS, images, or any other actual files that do not reside in such non-existent directories.
My CSS resides in the same directory as view.php (public_html), but the images are (slightly wrongly) in public_html/images. So we have <img src="images/blah.png" /> for example, but <link rel="stylesheet" type="text/css" href="sitecss.css" />
Clearly I have misunderstood something in mod_rewrite, and would love to know what. My present solution seems rather a hack:
RewriteRule ^articles/([[:digit:]]+)$ /$1 [NC,R,L]
RewriteRule ^([[:digit:]]+)$ view.php?id=$1 [NC]
This works, but I feel it ought to be possible to avoid the external redirect, which removes the 'articles' from the URL. Live-with-able, but would be great to fix.
There are several choices to avoid problems with link resolution:
Jim
It is a rewrite that you need just there.
You also need a redirect in the reverse direction so that nothing can directly access the dynamic URLs.
So:
(www.)?domain.com/filename?parameter=value --> 301 redirect --> www.domain.com/value/value/
/value/value/ --> internal rewrite --> /filename?parameter=value