1

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: https://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
3
  • 4
    Is this something for here? I'd think Server Fault would be a better place for this question.
    – Mark Loeser
    Feb 1, 2011 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, 2011 at 17:50

2 Answers 2

0

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 )

1
  • @user972 - thanks. How is this useful?
    – siliconpi
    Feb 3, 2011 at 16:48
-1

Probably you should include httpd.conf to apache2.conf

Go to /etc/apache2/apache2.conf and add

Include httpd.conf

there.

After that restart apache.

4
  • This doesn't answer the original question. Not all flavours of Linux use apache2.conf in any case.
    – richardb
    Feb 22, 2016 at 8:10
  • It may answer the original question. And may not. It depends on whether httpd.conf already included or not. Are you disagree on that? And of course, you are right about "not all flavours of Linux use apache2.conf", thanks!
    – Hamma
    Feb 22, 2016 at 8:21
  • And I did not noticed it was 2011 year`s question. Will be more careful next time.
    – Hamma
    Feb 22, 2016 at 8:44
  • It's possible but a bit unlikely. And as you say, it's an old question. Welcome to SF!
    – richardb
    Feb 22, 2016 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .