【发布时间】:2017-03-15 03:05:19
【问题描述】:
我看过这个:htaccess remove index.php from url,但它不起作用,并且在 cmets 中似乎对最佳答案存在分歧。
如果我输入 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 在 url 中时,它当前可用。
我也尝试过: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/ url 进行协调?
编辑:
以上只针对root (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]
【问题讨论】:
-
指向另一个答案的链接是正确的。我不确定你为什么改变了
RewriteRule的方式。将其改回RewriteRule ^(.*)$ /index.php?/$1 [L]。它也不需要在IfModule之间。应该只使用RewriteEngine On -
@thickguru 我改变了它,因为我想重写的唯一网址是那些以
/thanksgiving/开头的网址
标签: wordpress .htaccess laravel