Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess从url中删除index.php和其他_Php_.htaccess - Fatal编程技术网

.htaccess从url中删除index.php和其他

.htaccess从url中删除index.php和其他,php,.htaccess,Php,.htaccess,我有一个问题,谷歌用错误的url索引了一些页面 他们正在索引的url是: 1. http://www.mydomain.com/index.php?a=profile&u=john 2. http://www.mydomain.com/index.php?a=page&b=about 3. http://www.mydomain.com/index.php?a=settings&b=avatar 4. http://www.mydomain.com/index.php?a

我有一个问题,谷歌用错误的url索引了一些页面

他们正在索引的url是:

1. http://www.mydomain.com/index.php?a=profile&u=john
2. http://www.mydomain.com/index.php?a=page&b=about
3. http://www.mydomain.com/index.php?a=settings&b=avatar
4. http://www.mydomain.com/index.php?a=feed
5. http://www.mydomain.com/index.php?a=feed&filter=picture
6. http://www.mydomain.com/index.php?a=post&m=32
7. http://www.mydomain.com/index.php?lang=english
8. http://www.mydomain.com/index.php?a=messages&u=john&id=4
9. http://www.mydomain.com/index.php?a=feed&logout=1
我需要它重定向到:

1. http://www.mydomain.com/john or http://www.mydomain.com/profile/john
2. http://www.mydomain.com/about or http://www.mydomain.com/page/about
3. http://www.mydomain.com/settings/avatar
4. http://www.mydomain.com/feed
5. http://www.mydomain.com/feed/picture or http://www.mydomain.com/feed/filter/picture
6. http://www.mydomain.com/message/32
7. http://www.mydomain.com/lang/english
8. http://www.mydomain.com/messages/john
9. http://www.mydomain.com/logout or http://www.mydomain.com/feed/logout
.htaccess不是我的强项,因此任何帮助都将不胜感激

提前谢谢

编辑:

  • 好的,我使用Dan Trimper和Jon Lin的两种方法实现了它。首先,我使用Dan Trimper方法生成mod rewrite url。例如
    http://www.mydomain.com/index.php?a=page&b=about
    ,因此在生成后,它将生成如下url
    RewriteRule^([^/]*)/([^/]*)$/index.php?a=$1&b=$2[L]

  • 第二,生成后,我使用第二种方法将url重定向到
    http://www.mydomain.com/page/about
    使用Jon-Lin方法:

    RewriteCond%{THE_REQUEST}^[A-Z]{3,9}\/index.php\?A=page&b=([^&\ ]+)是否重写规则^/page/%1?[L,R=301]

  • 谢谢大家!


  • 编辑2:由于冲突,无法在上面工作。更准确的解决方案转到本主题

    尝试将以下规则添加到文档根目录中的htaccess文件中:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=profile&u=([^&\ ]+)
    RewriteRule ^ /profile/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=page&b=([^&\ ]+)
    RewriteRule ^ /page/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=settings&b=([^&\ ]+)
    RewriteRule ^ /settings/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&logout=1
    RewriteRule ^ /feed/logout? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&filter=([^&\ ]+)
    RewriteRule ^ /feed/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed
    RewriteRule ^ /feed/? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&filter=([^&\ ]+)
    RewriteRule ^ /feed/%1? [L,R=301]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=post&m=([^&\ ]+)
    RewriteRule ^ /message/%1? [L,R=301]
    

    等等等等。

    我刚开始使用.htaccess时也不是很精通

    看看这个网站和.htaccess生成器-它帮了我很多忙,我想它会解决你的问题


    它会在您配置后为您的应用程序预写规则,然后复制/粘贴到您的.htaccess文件。

    查看Mod rewrite谢谢。该网站去了正确的网址,但我得到404找不到。我需要像url重写或用户友好的url的东西。发动机也打开模块。页面示例,选项+FollowSymLinks RewriteEngine On RewriteCond%{THE_REQUEST}^[A-Z]{3,9}\/index\.php\?A=page&b=([^&\]+)RewriteRule^/page/%1?[R=301,L]@Napster如果
    http://www.mydomain.com/profile/john
    不存在,你到底为什么要将谷歌重定向到这些URL?我想修剪URL,这就像使用htaccess文件创建漂亮的URL一样。工作url将是这样的,并希望改变它像上面的OP。好吧,我得到它的工作使用丹Trimper和你的两种方法。谢谢谢谢我试试看。