简体   繁体   中英

Using mod_rewrite to mask a directory/file name in a URL

I've taken my site down for some prolonged maintenance and am using mod_rewrite to send all requests to a single page: www.mysite.com/temp/503.php

This is my .htaccess file which works fine.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/temp/503.php [NC]
RewriteRule .* /temp/503.php [R,L]

However, what I'd also like to be able to do is to hide /temp/503.php in the resulting URL from the visitor.

I know this is perhaps trivial and I'm sure fairly simple to achieve, but with my limited mod_rewrite skills I can't seem to get it to work.

Any help would be much appreciated.

Thanks.

Just get rid of the R flag in the rewrite rule, which tells the rule to redirect the request , thus changing the URL in the browser's location bar. So the rule would look like:

RewriteRule .* /temp/503.php [L]

which internally rewrites the requested URI instead of externally telling the browser that it's been moved to a new URL.

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