重写 htaccess,这样它就不需要重复自己
Rewrite htaccess so it doesn't need to repeat itself
我有一个很大的 htaccess 文件,可以为一个网站做所有的重定向。这是我对每个目录所做的:
RewriteRule ^CAKE_MIX/.php$ CAKE_MIX/index.php [R,L]
RewriteRule ^CAKE_MIX$ CAKE_MIX/ [R,L]
RewriteRule CAKE_MIX/faqs.php$ /faqs/faqs.php?cat=CAKE_MIX [QSA]
RewriteRule CAKE_MIX/index.php$ /overview/overview.php?cat=CAKE_MIX [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /CAKE_MIX/*
RewriteRule . /faqs/faqs.php?cat=CAKE_MIX&question=%{REQUEST_URI}
RewriteRule ^COOKIE_DOUGH/.php$ COOKIE_DOUGH/index.php [R,L]
RewriteRule ^COOKIE_DOUGH$ COOKIE_DOUGH/ [R,L]
RewriteRule COOKIE_DOUGH/faqs.php$ /faqs/faqs.php?cat=COOKIE_DOUGH [QSA]
RewriteRule COOKIE_DOUGH/index.php$ /overview/overview.php?cat=COOKIE_DOUGH [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /COOKIE_DOUGH/*
RewriteRule . /faqs/faqs.php?cat=COOKIE_DOUGH&question=%{REQUEST_URI}
我为 18 个不同的目录执行此操作。我将如何重写 htaccess 以说出类似 "for any of the following directories: COOKIE_DOUGH, CAKE_MIX,ICE_CREAM, follow these rules?" 的内容,然后规则可能类似于:
RewriteRule ^DIRECTORY/.php$ DIRECTORY/index.php [R,L]
而且只写一次?这可能吗?
您可以使用正则表达式交替:
RewriteRule ^(CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/\.php$ /index.php [R,L]
RewriteRule ^(CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)$ / [R,L]
RewriteRule (CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/faqs\.php$ /faqs/faqs.php?cat= [QSA]
RewriteRule (CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/index\.php$ /overview/overview.php?cat= [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/
RewriteRule . /faqs/faqs.php?cat=%1&question=%{REQUEST_URI}
我有一个很大的 htaccess 文件,可以为一个网站做所有的重定向。这是我对每个目录所做的:
RewriteRule ^CAKE_MIX/.php$ CAKE_MIX/index.php [R,L]
RewriteRule ^CAKE_MIX$ CAKE_MIX/ [R,L]
RewriteRule CAKE_MIX/faqs.php$ /faqs/faqs.php?cat=CAKE_MIX [QSA]
RewriteRule CAKE_MIX/index.php$ /overview/overview.php?cat=CAKE_MIX [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /CAKE_MIX/*
RewriteRule . /faqs/faqs.php?cat=CAKE_MIX&question=%{REQUEST_URI}
RewriteRule ^COOKIE_DOUGH/.php$ COOKIE_DOUGH/index.php [R,L]
RewriteRule ^COOKIE_DOUGH$ COOKIE_DOUGH/ [R,L]
RewriteRule COOKIE_DOUGH/faqs.php$ /faqs/faqs.php?cat=COOKIE_DOUGH [QSA]
RewriteRule COOKIE_DOUGH/index.php$ /overview/overview.php?cat=COOKIE_DOUGH [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /COOKIE_DOUGH/*
RewriteRule . /faqs/faqs.php?cat=COOKIE_DOUGH&question=%{REQUEST_URI}
我为 18 个不同的目录执行此操作。我将如何重写 htaccess 以说出类似 "for any of the following directories: COOKIE_DOUGH, CAKE_MIX,ICE_CREAM, follow these rules?" 的内容,然后规则可能类似于:
RewriteRule ^DIRECTORY/.php$ DIRECTORY/index.php [R,L]
而且只写一次?这可能吗?
您可以使用正则表达式交替:
RewriteRule ^(CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/\.php$ /index.php [R,L]
RewriteRule ^(CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)$ / [R,L]
RewriteRule (CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/faqs\.php$ /faqs/faqs.php?cat= [QSA]
RewriteRule (CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/index\.php$ /overview/overview.php?cat= [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(CAKE_MIX|COOKIE_DOUGH|ICE_CREAM)/
RewriteRule . /faqs/faqs.php?cat=%1&question=%{REQUEST_URI}