doucuodan0897 2014-04-19 23:09
浏览 22
已采纳

没有.php的htaccess mod_rewrite

I'm having trouble with htaccess because I would like to have my URLs SEO friendly. And that's all good but I can't go on the URL without using .php

My URL is:

http://rasolutions.eu/blogitem?id=3

And I want it to be:

http://rasolutions.eu/blogitem/3/

I've searched online and I've written code that made it work, the only problem is that I can't go to the URL unless I use .php My htaccess code is this(I'm a noob if it comes to htaccess):

ErrorDocument 404 /404.php

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]

# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]

RewriteEngine On
RewriteRule    ^blogitem/([0-9]+)/$    blogitem.php?id=$1    [NC,L]
RewriteEngine On
RewriteRule    ^blog/([0-9]+)/$    blog.php?page=$1    [NC,L]

# Home redirect.
DirectoryIndex home.php

Thank you very much for helping! Sorry for the bad English, it isn't my mother tongue.

  • 写回答

2条回答 默认 最新

  • duanguan1573 2014-04-19 23:19
    关注

    Try this:

    ErrorDocument 404 /404.php
    
    Options +MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    
    # WWW to not WWW.
    RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
    RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]
    
    # No PERL access/
    RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
    RewriteRule .* – [F,L]
    
    RewriteEngine On
    RewriteRule    ^blogitem/([0-9]+)/$    blogitem.php?id=$1    [NC,L]
    RewriteEngine On
    RewriteRule    ^blog/([0-9]+)/$    blog.php?page=$1    [NC,L]
    
    # Home redirect.
    DirectoryIndex home.php
    

    Multiviews should allow Apache to search out a nearest match, e.g. without the ".php" extension.

    Best of luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用