我正在开发一个允许用户创建自定义名称的社交网络应用程序。我创建了一个名为" images"的虚拟测试帐户。所以我的URL地址是www.example.com/images。我遇到的问题是,当我去搜索用户www.example.com/images时,我被转发到名为" images /"的目录中。相反www.example.com/images/ ...如何忽略该目录并转而转发到虚荣URL页面?
感谢您提前提供任何帮助。
这是我目前使用的htaccess代码
Options +FollowSymLinks
RewriteEngine On
#hide htaccess file from view
<Files .htaccess>
order allow,deny
deny from all
</Files>
#disable directory listing
Options -Indexes
#Vanity URL
RewriteRule ^([a-zA-Z0-9_]+)$ profile.php?u=$1
#Force WWW
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#errorRedirect
ErrorDocument 400 http://www.example.com/errors/badrequest.php
ErrorDocument 403 http://www.example.com/errors/forbid.php
ErrorDocument 404 http://www.example.com/errors/notfound.php
ErrorDocument 500 http://www.example.com/errors/server.php
答案 0 :(得分:1)
这是因为mod_dir
添加了一个尾部斜杠并进行了重定向。您可以使用以下代码:
#errorRedirect
ErrorDocument 400 http://www.example.com/errors/badrequest.php
ErrorDocument 403 http://www.example.com/errors/forbid.php
ErrorDocument 404 http://www.example.com/errors/notfound.php
ErrorDocument 500 http://www.example.com/errors/server.php
# turn directory slash off
DirectorySlash Off
#disable directory listing
Options +FollowSymLinks -Indexes
RewriteEngine On
#hide htaccess file from view
<Files .htaccess>
order allow,deny
deny from all
</Files>
#Force WWW
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#Vanity URL
RewriteRule ^(\w+)/?$ profile.php?u=$1 [L,QSA]