简体   繁体   中英

RewriteRule in .htaccess showing rewritten url in address bar

Apologies if this has been asked before but I've searched all over for an answer to this but I haven't been able to find a satisfactory solution.

I've got the following .htaccess file in my httpdocs:

Options +FollowSymlinks
RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/users/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ users/$1 [L]

This correctly maps "www.example.com/joebloggs" to "www.example.com/users/jobloggs" and the appropriate index page is correctly shown.

The problem is "www.example.com/users/jobloggs" is shown in the address bar instead of the original (short) url. Would really appreciate any help on this.

If you're saying it's loading a DirectoryIndex file (eg index.html / index.php ), then I'd say the lack of a trailing slash in your RewriteRule substitution is the problem. Try something like:

RewriteRule ^(.+?)/?$ users/$1/ [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM