php or /index.html to /
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
# Rewrite category pages
RewriteRule ^.*-d([0-9]+)/.*-c([0-9]+)/page-([0-9]+)/?$ index.php?Depart
mentId=$1&CategoryId=$2&Page=$3 [L]
RewriteRule ^.*-d([0-9]+)/.*-c([0-9]+)/?$ index.php?DepartmentId=$1&Cate
goryId=$2 [L]
# Rewrite department pages
RewriteRule ^.*-d([0-9]+)/page-([0-9]+)/?$ index.php?DepartmentId=$1&Pag
e=$2 [L]
RewriteRule ^.*-d([0-9]+)/?$ index.php?DepartmentId=$1 [L]
# Rewrite subpages of the home page
RewriteRule ^page-([0-9]+)/?$ index.php?Page=$1 [L]
# Rewrite product details pages
RewriteRule ^.*-p([0-9]+)/?$ index.php?ProductId=$1 [L]
?– Tip If you don??™t have a friendly code editor, creating a file that doesn??™t have a name but just an extension,
such as .htaccess, can prove to be problematic in Windows. The easiest way to create this file is to open
Notepad, type the contents, go to Save As, and type ".htaccess" for the file name, including the quotes.
The quotes prevent the editor from automatically appending the default file extension, such as .txt for
Notepad.
3. At this moment, your web site should correctly support keyword-rich URLs, in the form described prior to
starting this exercise. For example, try loading http://localhost/tshirtshop/nature-d2/. The
result should resemble the page shown in Figure 7-2.
Pages:
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299