How can I improve my website's rewrite rules ?

Discuss practical ways rearrange URLs using mod_rewrite.

How can I improve my website's rewrite rules ?

Postby 2levelsabove » Fri Nov 14, 2008 1:09 pm

There are still some issues if you explore the site.

1). for example I want non existing pages to go to 404.shtml
2). I want the whole site in http format except the payment page which I always want to be at https://alltherides.com/payment.php
3). I just feel that my htaccess file can be made better


C'mon Richard you can do it. You are the smartest mod rewrite person I have ever encountered. Thanks again man

Code: Select all

AddHandler application/x-httpd-php5 .html .htm .shtml .xml


RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^alltherides\.com [NC]
RewriteRule ^(.*)$ http://alltherides.com/$1 [L,R=301]



RewriteRule ^.+_for_sale_([0-9]+).html$ http://alltherides.com/viewlisting.php?id=$1
RewriteRule ^.+-images([0-9]+).html$ http://alltherides.com/viewallimages.php?id=$1


RewriteRule ^.+_Reviews_([0-9]+)_([0-9]+)_([0-9]+).html$ http://alltherides.com/yearmakemodelreviews.php?year=$1&make=$2&model=$3

RewriteRule ^.+_Review_([0-9]+).html$ http://alltherides.com/yearmakemodelreview.php?id=$1

RewriteRule ^.+_Specifications_([0-9]+).html$ http://alltherides.com/modelspecification.php?id=$1


RewriteRule ^.+_History_([0-9]+).html$ http://alltherides.com/getManufacturerHistory.php?id=$1

RewriteRule ^.+_Model_Info_([0-9]+).html$ http://alltherides.com/getModelHistory.php?id=$1

RewriteRule ^.+_Dealer_([0-9]+).html$ http://alltherides.com/viewDealerProfile.php?id=$1

RewriteRule   ^([A-Za-z0-9-]+)/?$               http://alltherides.com/viewDealerProfile.php?id=$1        [L]

SECFILTERENGINE OFF
SECFILTERSCANPOST OFF


2levelsabove
 
Posts: 12
Joined: Sun Feb 03, 2008 11:38 pm

Postby richardk » Fri Nov 14, 2008 1:39 pm

Try
Code: Select all
AddHandler application/x-httpd-php5 .html .htm .shtml .xml
Options +FollowSymLinks
SECFILTERENGINE OFF
SECFILTERSCANPOST OFF

RewriteEngine On

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^payment\.php$ https://example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{SERVER_PORT} !^80$
RewriteRule !^payment\.php$ http://example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteRule ^.+_for_sale_([0-9]+)\.html$                  /viewlisting.php?id=$1                             [QSA,L]
RewriteRule ^.+-images([0-9]+)\.html$                     /viewallimages.php?id=$1                           [QSA,L]
RewriteRule ^.+_Reviews_([0-9]+)_([0-9]+)_([0-9]+)\.html$ /yearmakemodelreviews.php?year=$1&make=$2&model=$3 [QSA,L]
RewriteRule ^.+_Review_([0-9]+)\.html$                    /yearmakemodelreview.php?id=$1                     [QSA,L]
RewriteRule ^.+_Specifications_([0-9]+)\.html$            /modelspecification.php?id=$1                      [QSA,L]
RewriteRule ^.+_History_([0-9]+)\.html$                   /getManufacturerHistory.php?id=$1                  [QSA,L]
RewriteRule ^.+_Model_Info_([0-9]+)\.html$                /getModelHistory.php?id=$1                         [QSA,L]
RewriteRule ^.+_Dealer_([0-9]+)\.html$                    /viewDealerProfile.php?id=$1                       [QSA,L]
RewriteRule ^([a-z0-9-]+)/?$                              /viewDealerProfile.php?id=$1                    [NC,QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby 2levelsabove » Fri Nov 14, 2008 2:16 pm

Richard,
wow that was fast.
ok that worked good.

however when i try going to http://alltherides.com/hhhhhhs/ (hhhhhs) being a non exist directory...look at the 404 message.
2levelsabove
 
Posts: 12
Joined: Sun Feb 03, 2008 11:38 pm

Postby richardk » Fri Nov 14, 2008 2:55 pm

An Apache 404 error can't be sent if a rule matches the request (the last rule matches the /hhhhhs/ request). If you want to send a 404 error, either limit the rule to only match exactly what you want, or edit your script to send a 404 header. In PHP, this can be done with header() (the third argument).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby 2levelsabove » Sat Nov 15, 2008 10:38 am

Richard,

I got it.

Thank you yet again for your outstanding help .

You are by far the most helpful moderator I have ever come across.


If you are ever in Dallas Ft Worth area, make sure to contact me and we go for lunch.


Kudos
2levelsabove
 
Posts: 12
Joined: Sun Feb 03, 2008 11:38 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 11 guests

cron