Mod_Rewrite 不断变化 url

Mod_Rewrite for constantly changing url

我有一个 url,假设它是 blog.art。ca/Customer/AAAABBBB/index。html 我想隐藏客户和 AAAABBBB。现在 AAAABBBB 可以是任何 8 个字符的字母数字代码。

Options +FollowSymLinks -Multiviews -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Customer/(.*)$ / [L,R]
</IfModule>

我已经尝试了很多方法,但是,我要么得到 ERR_TOO_MANY_REDIRECTS,要么只是导致服务器崩溃。如有任何建议,我们将不胜感激!

您仍然需要允许请求到达实际请求的资源,因此您需要两组规则,一组给浏览器,以显示新的更短的 URL(301 永久重定向),第二组撤消此映射回到原始 URL,以便 Apache 可以找到正确的东西来提供服务,例如。

RewriteBase /

# Remove Customer/AAAABBB from the URL shown in the browser.
RewriteCond %{QUERY_STRING} !customer=
RewriteRule ^Customer/([^/]+)/(.*) /?customer= [L,QSA,R=301]

# Internally undo any masked rewrites.
RewriteCond %{QUERY_STRING} customer=([^&]+)
RewriteRule (.*)  /Customer/%1/ [L]