0

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

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

我已经尝试了很多东西,但是,我要么得到 ERR_TOO_MANY_REDIRECTS,要么只是导致服务器崩溃。我们欢迎所有的建议!

4

1 回答 1

2

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

RewriteBase /

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

# Internally undo any masked rewrites.
RewriteCond %{QUERY_STRING} customer=([^&]+)
RewriteRule (.*)  /Customer/%1/$1 [L]
于 2015-08-16T22:46:35.193 回答