为什么.htaccess在实时站点上不起作用?

时间:2018-12-26 00:24:03

标签: php .htaccess url url-rewriting

我需要将网址重写为“漂亮”而不是查询:它们需要为/ kw / blah而不是kw.php?kw = blah。我已经使用在线检查器对代码进行了多次测试,他们说它在语法上正确/正确。

我曾经检查过的两个站点是:https://htaccess.madewithlove.be(URL测试是使用/ kw / melbourne-web-design和http://www.htaccesscheck.com

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} blueshiftwebservices\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://blueshiftwebservices.com/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^kw/([^/]*)$ landing.php?kw=$1 [L]
</IfModule>

# END WordPress

我收到的404页面错误仅是用漂亮的url而不是包含查询的url找不到的。

该实时站点绝对是指.htaccess文件,所以我不知道该怎么办?

1 个答案:

答案 0 :(得分:3)

规则RewriteRule . /index.php [L]匹配所有URL。因此,您必须在规则RewriteRule ^kw/([^/]*)$ landing.php?kw=$1 [L]之前插入它。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # redirect to https
    RewriteCond %{HTTP_HOST} blueshiftwebservices\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://blueshiftwebservices.com/$1 [R,L]

    # are you sure you need it?
    RewriteRule ^index\.php$ - [L]

    # make it "pretty"
    RewriteRule ^kw/([^/]*)$ landing.php?kw=$1 [L]

    # process the rest
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>