htaccess没有在index.php页面或默认页面上重定向我

时间:2017-02-28 15:21:51

标签: php .htaccess redirect

当我尝试继续 http://localhost/themobilesapp 时,它仍会将我重定向到 specification.php 页面,而不是重定向我 index.php

现在,我输入 http://localhost/themobilesapp/index.php

进入我的主页

这是我的完整htaccess代码。

Options +FollowSymLinks -MultiViews -Indexes

<IfModule mod_rewrite.c>

DirectoryIndex index.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 404error.php

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1 [L]

RewriteRule ^news/([A-Za-z0-9-]+)?$ news.php?url=$1 [L]

</IfModule>

如何通过输入 http://localhost/themobilesapp 将其重定向到index.php?

2 个答案:

答案 0 :(得分:1)

尝试以下规则,

DirectoryIndex index.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 404error.php

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1 [L]

RewriteRule ^news/([A-Za-z0-9-]+)?$ news.php?url=$1 [L]

RewriteRule ^$ /themobilesapp/index.php [R=301,L]

答案 1 :(得分:0)

我没有在你的htaccess中看到index.php

我认为你的意思是:

0x5a

这意味着此重写之下的其他重定向将无法执行。订单很重要;必要时使用L标志。

你的正则表达式:

RewriteRule ^(.*)$ index.php [L]

匹配所有内容(即使是空字符串;如示例所示)。如果你离开最后一个?出;另一个字符串不是可选的:

RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1 [L]
相关问题