htaccess从url中删除index.php
我有一个问题,谷歌已经索引了一些页面与错误的url。
他们索引的url是:
http://www.example.com/index.php/section1/section2 我需要它redirect到:
 http://www.example.com/section1/section2 
.htaccess不是我的专长,所以任何帮助将不胜感激。
提前致谢。
 这是从URL中隐藏index.php的基本规则。 把它放在你的根.htaccess文件中。 
  mod_rewrite必须使用PHP启用,这将适用于PHP版本高于5.2.6。 
 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L] 
 要从URL中删除index.php ,并将访问者redirect到非index.php版本的页面: 
 RewriteBase / RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] 
 这将干净地将/index.php/myblogredirect到/myblog 。 
使用301redirect将保留谷歌search引擎排名。
 RewriteEngine On RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /(.*)index\.php($|\ |\?) RewriteRule ^ /%1 [R=301,L] 
执行以下步骤
1.确保主机/您的电脑mod_rewrite模块处于活动状态。 如果不活跃,则尝试以某种方式激活,打开httpd.conf文件。 你可以在phpinfo.php中查看。
更改此设置:
 #LoadModule rewrite_module modules/mod_rewrite.so 
要重新启动wamp
 LoadModule rewrite_module modules/mod_rewrite.so 
2.然后转到.htaccess文件,并尝试修改为:
 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] 
如果上面不行,试试这个:
 RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php 
3.将.htaccess文件移动到根目录,其中是index.php。
 www OR root folder - index.php - .htaccess 
假设现有的url是
 http://example.com/index.php/foo/bar 
我们想把它转换成
  http://example.com/foo/bar 
您可以使用以下规则:
 RewriteEngine on #1) redirect the client from "/index.php/foo/bar" to "/foo/bar" RewriteCond %{THE_REQUEST} /index\.php/(.+)\sHTTP [NC] RewriteRule ^ /%1 [NE,L,R] #2)internally map "/foo/bar" to "/index.php/foo/bar" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ /index.php/$1 [L] 
在特技#1中,我们首先匹配请求string并捕获/index.php/中的所有内容,并将捕获的值保存在%1 var中。 然后,我们发送浏览器到一个新的url。 #2在内部处理请求。 当浏览器到达/ foo / bar时 ,#2rule将新的url重写到原始位置。
从WordPress的网站中删除index.php的步骤。
-  检查你应该在你的服务器上启用mod_rewrite。 检查是否启用 – 使用下面的命令在根文件夹中创build1个文件phpinfo.php。
 
现在运行这个文件 – http://www.yoursite.com/phpinfo.php,它将在Load modules部分显示mod_rewrite。 如果未启用,请在terminal执行以下命令。
sudo a2enmod重写sudo服务apache2重新启动
- 
确保您的.htaccess文件存在于您的WordPress根文件夹中,如果没有创build.htaccess文件,请将以下代码粘贴到.htaccess文件中: 开始WordPressRewriteEngine On RewriteBase / RewriteRule ^ index.php $ – [L] RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule。 /index.php [L] 结束WordPress
- 
进一步允许.htaccess到666,以便它变得可写,现在你可以在你的WordPress的永久链接进行更改。 
- 
现在转到设置 – >永久链接 – >并更改为您需要的url格式。 删除此代码/index.php/%year%/%monthnum%/%day%/%postname%/并在自定义结构中插入以下代码:/%postname%/ 
- 
如果仍然没有成功,然后检查您的主机,我的digitalocean服务器,所以我自己清理 
编辑文件/etc/apache2/sites-enabled/000-default.conf
在DocumentRoot / var / www / html之后添加了这一行
AllowOverride全部
重新启动你的Apache服务器
注意:/ var / www / html将成为你的文档根目录