相关疑难解决方法(0)

存在重写文件路径中的RewriteRule检查文件

如何使用ModRewrite检查缓存文件是否存在,如果存在,则重写缓存文件,否则重写为动态文件.

例如,我有以下文件夹结构:

pages.php
cache/
  pages/
   1.html
   2.html
   textToo.html
   etc.

你如何为此设置RewriteRules,所以请求可以像这样发送:

example.com/pages/1

如果缓存文件存在,则重写缓存文件,如果缓存文件不存在,则重写为pages.php?p = 1

它应该是这样的:(请注意,这不起作用,否则我不会问这个)

RewriteRule ^pages/([^/\.]+) cache/pages/$1.html [NC,QSA]
RewriteCond %{REQUEST_FILENAME} -f [NC,OR] 
RewriteCond %{REQUEST_FILENAME} -d [NC] 
RewriteRule cache/pages/([^/\.]+).html pages.php?p=$1 [NC,QSA,L]

我可以使用PHP来粗略地做这个,但我认为必须使用mod_rewrite.

apache mod-rewrite caching

14
推荐指数
2
解决办法
1万
查看次数

终极移动.htaccess重定向

我已经使用下面的.htaccess代码为移动/桌面重定向提供了一个不错的工作解决方案,但是如果有人可以提供帮助,还有一些可以真正实现最终的增强功能.

目录设置:

  • 桌面网站:website.com
  • 移动网站:m.website.com

Cookie启用链接:

  • 从桌面站点移动到移动站点,设置cookie以保持在移动设备上:http://m.website.com?m = 1
  • 从移动站点到桌面站点,设置cookie以保持在桌面上:http://www.website.com?m = 0

当前.htaccess文件:

RewriteEngine on

# Check if this is the desktop to mobile query string
RewriteCond %{QUERY_STRING} (^|&)m=1(&|$)

# Set a cookie, and skip the next 2 rules 
RewriteRule ^ - [CO=mredir:1:%{HTTP_HOST},S=2]

# Check if this is the mobile to desktop query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)

# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]

# Check if we're not already …
Run Code Online (Sandbox Code Playgroud)

.htaccess mobile redirect

6
推荐指数
1
解决办法
3278
查看次数

标签 统计

.htaccess ×1

apache ×1

caching ×1

mobile ×1

mod-rewrite ×1

redirect ×1