简体   繁体   中英

how to redirect all page request to one page without url change

I want to redirect all pages on my site (including index) to UnderWork.html and I'm doing this using .htaccess with this code:

RewriteEngine on
RewriteRule ^(.*)$ UnderWork.html

...and its works fine. Now I am adding some more code to my .htaccess to redirect all traffic to the non-www domain and now my code looks like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.in
RewriteRule ^(.*)$ http://domain.in$1 [R=permanent,L]
RewriteRule ^(.*)$ UnderWork.html

Here is where I have a problem. If I enter a URL like: domain.in/xyz then it works as before, but if I use a URL like: www.domain.in/xyz then Apache converts it to coincart.inxyz/ .

What am I doing wrong here? How can I get what i want? Thanks in advance.

Below are rules that work for me:

RewriteEngine On

# Adding trailing slash for directory requests.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/www$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.+[^/])$ http://example.com/$1/ [R=permanent]

# External redirection from www subdomain to non-www domain.
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^/?(.*) http://example.com/$1 [L,R=permanent]

# Internal redirection to index.php for nonexistent URLs.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|png|gif)$
RewriteRule . /index.php [L,QSA]

To show a custom page when a directory root (domain root in particular) is requested, use the Apache's DirectoryIndex directive:

DirectoryIndex UnderWork.html

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