Перемещение правил mod_rewrite в.htaccess в httpd.conf

У меня есть огромный набор правил перезаписи URL, которые я пытаюсь:

  1. оптимизировать
  2. переход к использованию в httpd.conf

Но я сталкиваюсь с проблемами при получении конечного продукта для работы.

Примечание: есть оптимизации, о которых упоминали другие: https://webmasters.stackexchange.com/questions/4237/url-rewritten-pages-take-much-longer-to- (пожалуйста, ознакомьтесь с этим)

Примечание: следующее прекрасно работает в файле.htaccess

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

Следующее НЕ работает нормально в 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

2 ответа

Я просто собираюсь оставить это здесь:

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

Контекст: конфигурация сервера, виртуальный хост, каталог,.htaccess

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

Возможно, вам следует включить httpd.conf в apache2.conf

Перейдите в /etc/apache2/apache2.conf и добавьте

Include httpd.conf

там.

После этого перезапустите apache.

Другие вопросы по тегам