duanniu3385 2012-10-20 00:56
浏览 49
已采纳

删除文件扩展名并允许“伪目录”?

I'm creating a fairly simple website. There are two static pages (Home and Portfolio) in the root folder, and Wordpress in /blog. The static pages includes Wordpress using require_once("blog/wp-config.php");.

The portfolio page will be using Javascript (either History.JS or Crossroads/Hasher) to "push" URLs representing the categories and albums. For example, clicking "Weddings" on the left will result in portfolio/weddings, and an album would be portfolio/weddings/jane-jon-smith. These files need to be available when accessed directly (I send you a link to the album).

Right now, I have it set up so that the static pages are accessible from index.php and portfolio.php. I was able to remove the file extensions using the following .htaccess directives:

# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php [L]

But when I try to visit a URL such as portfolio/weddings, I get a 404 error because that isn't a valid directory or file. I've been searching, but can't seem to find anything related, other than how to remove the extension (which I have working).

How do I remove the file extension and also allow direct access to these "fake" directories?

  • 写回答

2条回答 默认 最新

  • dpwu16132 2012-10-20 02:15
    关注

    After posting my comment to the question, it hit me that maybe I should redirect anything matching "portfolio/*" to portfolio.php, and from there I can deal with the path using a few functions (which is successfully working now).

    All I did was add this line immediately after the rules I listed in the question:

    RewriteRule ^portfolio/([^/]+) /portfolio.php?$1 [NC]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口