嘿,所以我正在尝试让我的htaccess文件做两件事:
1)如果用户输入http://dstealth.com/i
或http://dstealth.com/i/some/other/address
我希望htaccess文件使用http://dstealth.com/z_index/
或http://dstealth.com/z_index/some/other/address
2)我还希望htaccess文件重定向用户,如果他们使用旧地址。例如,如果用户键入http://dstealth.com/z_index
或http://dstealth.com/z_index/some/other/address
我希望URL显示为http://dstealth.com/i/some/other/address
基本上在任何时候都将z_index
替换为i
,即使目录i
不存在并且z_index
仍然是正在使用的目录。
我已经尝试了很多东西,但它似乎不起作用,因为它不断将我重定向到我的 404 页面。
我的 .htaccess 文件:
ServerSignature Off
ErrorDocument 403 /error_pages/403.php
ErrorDocument 404 /error_pages/404.php
ErrorDocument 500 /error_pages/500.php
IndexIgnore *
RewriteEngine On # Turn on the rewriting engine - only needed once
Options -MultiViews
# Prevent directory listings
Options All -Indexes
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# Rewrite www.dstealth.com as dstealth.com
RewriteCond %{HTTP_HOST} ^www.dstealth.com [NC]
RewriteRule ^(.*)$ http://dstealth.com/$1 [R=301,NC]
# Rewrite /z_index/ as /i/
RewriteRule ^z_index/([^/.]+)$ /i/$1 [NC]
RewriteRule ^i/([^/.]+)$ /z_index/$1 [NC,L]
结果:
http://dstealth.com/z_index/
仍然看起来完全相同,不会更改为http://dstealth.com/i/
http://dstealth.com/i/
把我带到我的404页:(
我相信我通过以下代码得到了我想要的。如果有任何错误或效率低下,请告诉我:
RewriteCond %{THE_REQUEST} s/z_index [NC]
RewriteRule ^z_index/([^.]+).php$ /i/$1.php [R=302,L]
RewriteCond %{THE_REQUEST} s/z_index [NC]
RewriteRule ^z_index/([^.]+)$ /i/$1 [R=302,L]
RewriteCond %{THE_REQUEST} s/z_index [NC]
RewriteRule ^z_index/?$ /i/ [R=302,L]
RewriteRule ^i/([^.]+).php$ /z_index/$1.php [NC,L]
RewriteRule ^i/$ /z_index/?&%{QUERY_STRING} [NC,L]