Htaccess从URL中删除Index.php

时间:2016-11-01 21:46:34

标签: wordpress .htaccess laravel

我看了这个:htaccess remove index.php from url但它没有用,而且在评论中似乎对最佳答案存在分歧。

如果我输入http://www.example.com/thanksgiving/index.php/getThankyou,我会收到我想要提供的页面。

如果我输入http://www.example.com/thanksgiving/getThankyou,我会收到404。

我在htaccess中尝试了什么:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/thanksgiving/(.*)/$ /thanksgiving/index.php/$1 [L]
</IfModule>

我如何才能这样做/thanksgiving/getThankyou/或者网址中以/thanksgiving开头的任何网址都会导致提供适当的资源?同样,当index.php位于网址时,它目前可用。

我也尝试过:RewriteRule ^/thanksgiving/[^/]*/$ /thanksgiving/index.php/$1 [L]但这也不起作用......

编辑:似乎htaccess的一部分是由wordpress设置的,可能与上面所期望的行为相冲突:

同一个htaccess的wordpress部分是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

这有干扰吗?如何将此与不属于Wordpress应用程序的/thanksgiving/网址协调一致?

编辑:

以上只涉及根(public_html)htaccess,下面是/thanksgiving/本身的htaccess,请分析一下冲突,感谢您的帮助!

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteBase /
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
# Do not change this line. 
# Change example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 

# Change your_app_name to the subfolder name
RewriteCond %{REQUEST_URI} !^/thanksgiving/ 

# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Change your_app_name to the subfolder name
# Change example.com to your domain name
RewriteRule ^(.*)$ /thanksgiving/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ thanksgiving/index.php [L]

1 个答案:

答案 0 :(得分:1)

您需要从重写模式中删除前导斜杠

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:thanksgiving/)?(.*)$ /thanksgiving/index.php/$1 [L]
</IfModule>

否则规则将接受以双重斜杠开头的uri(即: // thanksgiving / )。