将.htaccess中的mod_rewrite规则移至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 

我只想在这里留下:

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

上下文:服务器configuration,虚拟主机, 目录 ,.htaccess

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

可能你应该把httpd.conf包含到apache2.conf

转到/etc/apache2/apache2.conf并添加

 Include httpd.conf 

那里。

之后,重新启动Apache。