Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何使用url名称更改将页面从http重定向到htpps_.htaccess_Redirect_Mod Rewrite_Url Rewriting_Friendly Url - Fatal编程技术网

.htaccess 如何使用url名称更改将页面从http重定向到htpps

.htaccess 如何使用url名称更改将页面从http重定向到htpps,.htaccess,redirect,mod-rewrite,url-rewriting,friendly-url,.htaccess,Redirect,Mod Rewrite,Url Rewriting,Friendly Url,我有以下问题 我需要两样东西: 从不安全HTTP重定向到安全HTTPS,然后 从https://example.com/index.html至https://example.com/work-for-us 我知道我可以通过以下方式获得的第一个: RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 第二个是使用 RewriteEngine on

我有以下问题

我需要两样东西:

  • 从不安全HTTP重定向到安全HTTPS,然后
  • https://example.com/index.html
    https://example.com/work-for-us
  • 我知道我可以通过以下方式获得的第一个:

    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    第二个是使用

    RewriteEngine on
    RewriteRule work-for-us index.html
    
    但有没有可能把这两者联系起来呢

    所以我有HTTP->HTTPS和/index.html->/为我们工作

    我对.htaccess文件没有太多的了解,我在网上读了一些东西,但没有找到任何能回答我问题的东西

    因此,将所有内容放在一起,我想更改以下URL:

    http://example.com/index.html
    到此
    https://example.com/work-for-us


    提前谢谢。

    基于您展示的样品,请尝试以下内容。 请确保在测试URL之前清除浏览器缓存

    RewriteEngine on
    ##First rule for applying https to URLs.
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    ##Second rule for serving homepage(only dns link) with index.html file.
    RewriteRule ^/?$ work-for-us [R=301]
    RewriteRule ^/?$ index.html [L]
    
    ##Third rule for serving non-existing directories/files with index.html
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.html [L]
    

    感谢分享您的努力,这意味着您正在点击链接
    http://example.com/index.html
    在浏览器中?并希望它在浏览器中更改为
    https://example.com/work-for-us
    ?请确认一下。我从谷歌进入网站,它会点击https://example.com(因为我使用了从HTTP到https的重写规则)。服务器上加载的文件是index.html。所以出现在URL栏中的是https://example.com。但回答你的问题——如果有人写了你写的东西,那么是的,我希望他们被重定向到你写的@RavinderSingh13