.htaccess伪静态问题

php中文网
发布: 2016-06-23 13:35:20
原创
916人浏览过

.htaccess伪静态问题

RewriteEngine on
Rewritebase /
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

我一直用这个,这个有个缺点是什么文件都给包含进去了

比如你访问whois.hangye5.com/womai.cn
这样是可以的
但是如果访问whois.hangye5.com/sitemaps/sitemap1.html
也会跑到index.php文件里去
我想这二个文件不要都跑index.php里去,要修改哪些

AI建筑知识问答
AI建筑知识问答

用人工智能ChatGPT帮你解答所有建筑问题

AI建筑知识问答 22
查看详情 AI建筑知识问答

回复讨论(解决方案)

#当目录存在时不做重写
RewriteCond %{REQUEST_FILENAME} !-d

#当文件存在时不做重写
RewriteCond %{REQUEST_FILENAME} !-f

whois.hangye5.com/sitemaps/sitemap1.html
也会跑到index.php文件里去,显然 sitemaps/sitemap1.html 是不存在的

 ^(.*)$ 把一切不存在的东西都包括进去了,所以 404 设置不会起作用(index.php 总是存在的)
你需要在那个 .* 上做文章

sitemaps/sitemap1.html 
这些也准备伪静态
这个情况下我要怎么办

请教个伪静态的问题


我在弄那个whois查询的时候伪静态


http://whois.xxx.com/womai.cn这个的


RewriteEngine on
Rewritebase /
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]


用了这个是可以的


但是我现在想在上面弄多一个文件伪静态
whois.xxx.com/sitemaps/sitemap1.html
whois.xxx.com/sitemaps/sitemap2.html
whois.xxx.com/sitemaps/sitemap3.html
这样的


不知道怎么弄,不知道怎么在里面添加内容
我自己添加的出问题了。

whois.xxx.com/sitemaps/sitemap1.html
这样的会转变成 index.php?domain=sitemaps/sitemap1.html
你在 index.php 中判断处理一下就可以了

这个不好判断的,还是要走到htaccess
因为这个东西又不是只有二样。

建议你好好看看框架的路由指派

比较man呀
弄完这个还要去弄其他网站

RewriteEngine on
ErrorDocument 404 /404.html
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 


这样不行

RewriteRule ^(.*)/sitemaps/sitemap(\d+)\.html$ $1/sitemaps/sitemap.php?domain=$2

不行,他还是会跑到index.php里去。这个问题估计在第一个伪静态那里出问题了

你那样当然不行!
次序问题
RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 [L]
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

RewriteEngine on
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)/sitemaps/sitemap(\d+)\.html$ $1/sitemaps/sitemap.php?domain=$2
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

这样的不行,估计是上一次影响了下一条

我有  [L] 你却没有

RewriteEngine on
ErrorDocument 404 /404.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 [L]
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

这样也不行,真的

再向上调
RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?domain=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

RewriteEngine on
ErrorDocument 404 /404.html
RewriteRule ^(.*)/\w+/[A-za-z]+(\d+)\.html$ sitemaps/sitemap.php?page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

不行,有什么办法修改index.php 那一行,我那一行的作用是
whois.hangye5.com/womai.cn 后面是域名

我行,你不行。不好说什么了
可能是你的思路就错了,因为给 RewriteRule 的串中不会含有域名

这个大家都这样弄的
whois.22.cn/womaicn

RewriteEngine on
ErrorDocument 404 /404.html
RewriteRule ^sitemaps/sitemap([0-9]+).html$ /sitemaps/sitemap.php?domain=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?domain=$1 [QSA,PT,L]

这样可以了

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号