将 .htaccess 中的 mod_rewrite 规则移至 httpd.conf

将 .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

答案1

我就把它留在这里:

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

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

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

答案2

也许你应该将 httpd.conf 包含到 apache2.conf 中

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

Include httpd.conf

那里。

之后重新启动 apache。

相关内容