doudai8083 2016-06-25 13:35
浏览 52
已采纳

关于mod_Rewrite的Apache htaccess问题

I got an .htaccess file must to rewrite URLs for SEO friendly website,

So when i click on eg. an article ( eg www.example.com/article/this-is-an-artcle/ ) must to redirect me to index.php?article=this-is-an-article.

Same thing I must to do with the category page and admin page, so for completeness is something like this

www.ex.com/index.php?article=example-article -> www.ex.com/article/example-article   
www.ex.com/index.php?category=example -> www.ex.com/category/example
www.ex.com/index.php?page=admin -> www.ex.com/adm

Instead of this I must to hide the index.php file from the URL.

I'm doing this, but produce a 404 error

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} . [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^article/([\w-]+)/?$ index.php?article=$1 [QSA,L,NC]

RewriteRule ^category/([\w-]+)/?$ index.php?category=$1 [QSA,L,NC]

RewriteRule ^adm/?$ index.php?page=admin [QSA,L,NC]

RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Unfortunately If I open the apache.err.log can't see errors relating to the RewriteEngine, so i've tried to use LogLevel alert rewrite:trace6 in my .htaccess file, but didn't produce log, also tried to put a rewrite.log file in site folder, and make 777 permissions, no change, file still blank.

EDIT: Since this file work in another server ( cloud9 IDE ) and here not ( AWS Ubuntu 14.04 ) I'm assuming that I miss some configuration. How I can enable the LOG to see what's happen?

  • 写回答

3条回答 默认 最新

  • duansha7025 2016-06-28 02:00
    关注

    andreaem, try this:

    RewriteEngine On
    
    
    RewriteRule ^article/([a-zA-Z-_]+)+$ index.php?article=$1 [L]
    
    RewriteRule ^category/([a-zA-Z-_]+)+$ index.php?category=$1 [L]
    
    RewriteRule ^adm$ index.php?page=admin [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 C++/QT设置函数调用条件(多个功能调用同一,且各自调用条件不同)
  • ¥15 UE5样条线生成的网格UV问题
  • ¥15 如何用最短的时间大致看懂springboot+vue的项目
  • ¥15 (有偿)懂数值分析和含时变参数微分方程的来
  • ¥15 layui父页的数据表格如何用弹窗页提交后的查询数据来更新数据表格内容?
  • ¥15 abaqus随机生成二维颗粒
  • ¥15 安装ansys许可证管理器时出现了这个问题,如何解决?
  • ¥100 高价求算法,利用智能手机传感器计算车辆的三轴g值
  • ¥15 Blazor server 数据库操作异常,如何解决?(语言-c#)
  • ¥15 uni-app开发APP运行到浏览器访问接口跨域