Reputation: 45
I am working on a social network application that would allow users to create a custom name. I created a dummy test account with the name "images" so my URL address would be www.example.com/images. The issue I'm having is when i go to search for the user www.example.com/images i am forwarded to the directory called "images/" instead www.example.com/images/ ...how can i ignore the directory and get forwarded to the vanity URL page instead?
Thanks for any help in advance.
This is the htaccess code that I'm currently using
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
Upvotes: 1
Views: 32
Reputation: 785128
This is happening because of mod_dir
adding a trailing slash and doing a redirect. You can use this code:
#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]
Upvotes: 1