使用htaccess mod_rewrite RewriteRule更改URL的外观

时间:2018-10-24 03:54:27

标签: apache .htaccess mod-rewrite url-rewriting

很难在任何地方找到有关Rewrite Engine语法的清晰说明。正则表达式很熟悉,但其余部分对我来说却是陌生的。

是否无法在地址栏中显示的URL中隐藏http://https://

我的目录如下。

public_html/
    example/
        index.php
        whatever.php

问题#1

这是当前正在发生的事情,显然发生在整个地方。

URL THAT IS TYPED IN                         URL THAT DISPLAYS

https://www.example.com -------------------> https://www.example.com
https://example.com -----------------------> https://example.com
http://www.example.com --------------------> https://www.example.com/example/index.php
http://example.com ------------------------> https://example.com/example/index.php
www.example.com ---------------------------> https://www.example.com/example/index.php
example.com -------------------------------> https://example.com/example/index.php

我想做的第一件事始终是强制执行以下操作。

URL THAT IS TYPED IN                          URL THAT DISPLAYS

https://www.example.com/example/index.php --> example.com/index
https://www.example.com --------------------> example.com
https://example.com ------------------------> example.com
http://www.example.com ---------------------> example.com
http://example.com -------------------------> example.com
www.example.com ----------------------------> example.com
example.com --------------------------------> example.com

问题#2

我想做的第二件事是清理子目录和文件的URL。

ACCESS TO THIS FILE PATH                      URL THAT DISPLAYS

example.com/example/index.php --------------> example.com/index

我知道可以使用以下RewriteRule完成此操作。

RewriteRule ^index /mydomain/index.php [NC]

但是无论如何,我也想强制以以下方式显示URL。

URL THAT IS TYPED IN                          URL THAT DISPLAYS

https://www.example.com/example/index.php --> example.com/index
https://example.com/example/index.php ------> example.com/index
http://www.example.com/example/index.php ---> example.com/index
http:/example.com/example/index.php --------> example.com/index
www.example.com/example/index.php ----------> example.com/index
mydomain.com/example/index.php -------------> example.com/index

https://www.example.com/index.php ----------> example.com/index
https://example.com/index.php --------------> example.com/index
http://www.example.com/index.php -----------> example.com/index
http:/example.com/index.php ----------------> example.com/index
www.example.com/index.php ------------------> example.com/index
mydomain.com/index.php ---------------------> example.com/index

https://www.example.com/index --------------> example.com/index
https://example.com/index ------------------> example.com/index
http://www.example.com/index ---------------> example.com/index
http://example.com/index -------------------> example.com/index
www.example.com/index ----------------------> example.com/index
example.com/index --------------------------> example.com/index

我确实找到了this,,所以我将在晚餐后开始阅读。

我现在也遇到过this,但我仍在努力解决这个问题。

到目前为止我的进步

RewriteCond %{REQUEST_URI} ^/login$
RewriteRule ^login /index.php [NC]

RewriteCond %{REQUEST_URI} ^/dashboard$
RewriteRule ^dashboard /dashboard.php [NC]

RewriteCond %{REQUEST_URI} ^/logout$
RewriteRule ^logout /includes/destroy.php [NC]

RewriteCond %{HTTP_HOST} ^www\.birddogdata\.com$
RewriteRule ^(.*)$ https://birddogdata.com [R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我唯一要解决的问题是如何使example.com重定向到example.com/login

任何帮助将不胜感激。

0 个答案:

没有答案