dongnianwo8289 2018-08-07 18:26
浏览 56

.htaccess重定向到/ pages除非索引

I'm using a PHP router (AltoRouter) that allows me to define routes in all sorts of manners but doesn't do any kind of redirecting.

I want my '/' route to remain as is.

But if someone goes to anything other than '/' I have a wildcard route that grabs the name of that route, locates a twig file, and renders it based on name. So '/about' would locate about.twig and render it.

What I want to achieve is if someone goes to '/about' or '/contact', etc, then they'd be re-routed to '/pages/about', '/pages/contact', etc, but if they go to '/pages/about' directly then no re-route necessary.

My current .htaccess file looks like this:

RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Unfortunately I did a bunch of searching around and didn't really find how to do that specific conditional re-route/redirect. Especially not one that left the root '/' alone.

P.s. pages isn't actually a directory on the server. I just want to insert 'pages' before the page name.

  • 写回答

1条回答 默认 最新

  • dongwei5740 2018-08-08 12:28
    关注

    Try adding this immediately after RewriteEngine on:

    RewriteCond %{REQUEST_URI} !=/
    RewriteCond %{REQUEST_URI} !^/pages/
    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule (.*) /pages/$1 [R,L]
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了