简体   繁体   中英

How to redirect website to particular file?

There is a domain name. Let's say domain.com .

When the user types domain.com only, he should be redirected to the address domain.com/file.html . How can I do that with a .htaccess file?

Plus, what does RewriteRule ^index\\.php$ - [L] mean? Would it help me?

添加到您的.htaccess文件

DirectoryIndex file.html 

Check out this site: .htaccess tricks and tips It's a good reference for rewrite rules.

As for what does RewriteRule ^index.php$ - [L] mean. It's going to ignore anything with an index.php ending Rewrite Rule meaning

To redirect you can make a index page (the first page that the user visits)

DirectoryIndex file.html

modifying your .htaccess file according to this link .

For RewriteRule you need to able the mod_rewrite module in apache and then make in your .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule (.*) file.html [L]
</IfModule>

In the RewriteRule you can put regular expressions to identify the url and redirect the user to a file that you want (in this case you would redirect all your links to file.html ). More info here .

Moreover in the configuration file of the apache server by default is possible you have the next configuration:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml
</IfModule>

So, by default if you have a file called index.php in your webroot of your domain.com always that file would be called first.

Try putting the following in your .htaccess file located in the root of domain.com

RewriteEngine On
RewriteBase /

#put all the following rules before any other rules in the .htaccess file
RewriteRule ^file\.html$ - [L]

#domain.com or any subdomain 
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
#the root of domain   
RewriteCond %{REQUEST_URI} ^/?$ [NC]
#return file.html
RewriteRule . file.html [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