Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got a massive set of URL rewriting rules that I am trying to:

  1. optimize
  2. transition to use within httpd.conf

But I'm facing problems in getting the final product to work.

Note: There are optimizations that others have mentioned at: http://webmasters.stackexchange.com/questions/4237/url-rewritten-pages-take-much-longer-to- (please DO have a look at this)

Note: The following works perfectly within a .htaccess file

RewriteEngine On
RewriteBase /abcd/

RewriteRule ^.*/codelibrary/(.*)$ codelibrary/$1 [L]
RewriteRule ^.*/instructor_upload/images/(.*)$ instructor_upload/images/$1 [L]
RewriteRule ^.*/content/image/(.*)$ content/image/$1 [L]
RewriteRule ^.*/content/video/(.*)$ content/video/$1 [L]
RewriteCond %{REQUEST_URI} !instructor_upload/(.*)\.
RewriteRule ^.*/images/(.*)$ images/$1 [L]

RewriteRule ^.*/flowplayer/(.*)$ flowplayer/$1 [L]
RewriteRule ^.*/admin/ajax/(.*)$ admin/ajax/$1 [L]
RewriteCond %{REQUEST_URI} !admin/(.*)\.
RewriteRule ^.*/ajax/(.*)$ ajax/$1 [L]

RewriteRule ^.*/banner_images/(.*)$ banner_images/$1 [L]

RewriteRule (.*)invite/([a-zA-Z0-9\-]+)$ referer.php?instructor_name=$2 [L]
RewriteRule (.*)class/([0-9]+)/(.*)$ class-profile.php?class_id=$2 [L]
RewriteRule (.*)event/([0-9]+)/(.*)$ event-profile.php?event_id=$2 [L]
RewriteRule (.*)content/([0-9]+)/([a-zA-Z0-9\-\s]*)/([a-zA-Z0-9\-\s]*)/(.*)$ content-profile.php?content_id=$2&$4=$5 [L]
RewriteRule (.*)content/([0-9]+)/(.*)$ content-profile.php?content_id=$2 [L]
RewriteRule (.*)cms/([a-zA-Z\-\s]*).html$ static-pages.php?page_url=$2 [L]
RewriteRule ^([a-zA-Z0-9\-]+)$ teacher-profile-public.php?name=$1

RewriteRule (.*)cms/([a-zA-Z\-]*).html$ static-pages.php?page_url=$2 [L]

RewriteRule (.*)classes-events.html$ browse.php?type=classes-events [L]
RewriteRule (.*)instructors.html$ browse.php?type=instructors [L]
RewriteRule (.*)organizations.html$ browse.php?type=organizations [L]
RewriteRule (.*)random-content.html$ browse.php?type=content&random_order=1 [L]
RewriteRule (.*)content.html$ browse.php?type=content [L]

RewriteRule ^([a-zA-Z\-]*)/([a-zA-Z0-9\-\s]*)/([0-9]*)\.html$ browse.php?type=$1&catId=$3 [L]
RewriteRule ^([a-zA-Z\-]*)/([a-zA-Z0-9\-\s]*)/([a-zA-Z0-9\-\s]*)/([0-9]*)/([0-9]*)\.html$ browse.php?type=$1&catId=$4&subCatId=$5 [L]

RewriteRule (.*)search/all/(.*)$ searchall.php?type=all&srcval=$2 [L]
RewriteRule (.*)search/([a-zA-Z\s\-]*)/all/(.*)$ search.php?type=$2&srcval=$3&seeall=all [L]
RewriteCond %{REQUEST_URI} !all/(.*)\.
RewriteRule (.*)search/([a-zA-Z\s\-]*)/(.*)$ search.php?type=$2&srcval=$3 [L]
RewriteRule (.*)featured/([a-zA-Z\s\-]*)/(.*)/([0-9]*)\.html$ featured-listing.php?type=$2&catId=$4&feature=1 [L]
RewriteRule (.*)featured/(.*)$ featured-listing.php?type=$2&feature=1 [L]
ErrorDocument 404 http://www.example.com/abcd/404.php

The following does NOT work fine within a httpd.conf

RewriteEngine On

RewriteRule ^/abcd/.*/codelibrary/(.*)$ /abcd/codelibrary/$1 [L]
RewriteRule ^/abcd/.*/instructor_upload/images/(.*)$ /abcd/instructor_upload/images/$1 [L]
RewriteRule ^/abcd/.*/content/image/(.*)$ /abcd/content/image/$1 [L]
RewriteRule ^/abcd/.*/content/video/(.*)$ /abcd/content/video/$1 [L]
RewriteCond %{REQUEST_URI} !abcd/instructor_upload/(.*)\.
RewriteRule ^/abcd/.*/images/(.*)$ /abcd/images/$1 [L]

RewriteRule ^/abcd/.*/flowplayer/(.*)$ /abcd/flowplayer/$1 [L]
RewriteRule ^/abcd/.*/admin/ajax/(.*)$ /abcd/admin/ajax/$1 [L]
RewriteCond %{REQUEST_URI} !abcd/admin/(.*)\.
RewriteRule ^/abcd/.*/ajax/(.*)$ /abcd/ajax/$1 [L]

RewriteRule ^/abcd/.*/banner_images/(.*)$ /abcd/banner_images/$1 [L]

RewriteRule ^/abcd/invite/([a-zA-Z0-9\-]+)$ /abcd/referer.php?instructor_name=$1 [L]
RewriteRule ^/abcd/class/([0-9]+)/(.*)$ /abcd/class-profile.php?class_id=$1 [L]
RewriteRule ^/abcd/event/([0-9]+)/(.*)$ /abcd/event-profile.php?event_id=$1 [L]
RewriteRule ^/abcd/content/([0-9]+)/(.*)$ /abcd/content-profile.php?content_id=$1 [L]
RewriteRule ^/abcd/cms/([a-zA-Z\-\s]*).html$ /abcd/static-pages.php?page_url=$1 [L]
RewriteRule ^/abcd/([a-zA-Z0-9\-]+)$ /abcd/teacher-profile-public.php?name=$1 [L]

RewriteRule ^/abcd/cms/([a-zA-Z\-]*).html$ /abcd/static-pages.php?page_url=$1 [L]

RewriteRule ^/abcd/classes-events.html$ /abcd/browse.php?type=classes-events [L]
RewriteRule ^/abcd/instructors.html$ /abcd/browse.php?type=instructors [L]
RewriteRule ^/abcd/organizations.html$ /abcd/browse.php?type=organizations [L]
RewriteRule ^/abcd/random-content.html$ /abcd/browse.php?type=content&random_order=1 [L]
RewriteRule ^/abcd/content.html$ /abcd/browse.php?type=content [L]

RewriteRule ^/abcd/([a-zA-Z\-]*)/([a-zA-Z0-9\-\s]*)/([0-9]*)\.html$ /abcd/browse.php?type=$1&catId=$3 [L]
RewriteRule ^/abcd/([a-zA-Z\-]*)/([a-zA-Z0-9\-\s]*)/([a-zA-Z0-9\-\s]*)/([0-9]*)/([0-9]*)\.html$ /abcd/browse.php?type=$1&catId=$4&subCatId=$5 [L]

RewriteRule ^/abcd/search/all/(.*)$ /abcd/searchall.php?type=all&srcval=$1 [L]
RewriteRule ^/abcd/search/([a-zA-Z\s\-]*)/all/(.*)$ /abcd/search.php?type=$1&srcval=$2&seeall=all [L]
RewriteCond %{REQUEST_URI} !abcd/all/(.*)\.
RewriteRule ^/abcd/search/([a-zA-Z\s\-]*)/(.*)$ /abcd/search.php?type=$1&srcval=$2 [L]
RewriteRule ^/abcd/featured/([a-zA-Z\s\-]*)/(.*)/([0-9]*)\.html$ /abcd/featured-listing.php?type=$1&catId=$3&feature=1 [L]
RewriteRule ^/abcd/featured/(.*)$ /abcd/featured-listing.php?type=$1&feature=1 [L]
ErrorDocument 404 http://www.example.com/abcd/404.php
share|improve this question

migrated from codereview.stackexchange.com Mar 5 '11 at 16:37

This question came from our site for peer programmer code reviews.

4  
Is this something for here? I'd think Server Fault would be a better place for this question. –  Mark Loeser Feb 1 '11 at 13:58
    
@Mark - it is a code review question. Its not stereotypical code, I give you that - but code nevertheless for which I could use your input! :) –  siliconpi Feb 1 '11 at 17:50
    

1 Answer 1

I'm just going to leave this here:

https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule

Context: server config, virtual host, directory, .htaccess

( https://httpd.apache.org/docs/2.0/mod/directive-dict.html#Context )

share|improve this answer
    
@user972 - thanks. How is this useful? –  siliconpi Feb 3 '11 at 16:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.