欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

.htaccess伪静态问题

程序员文章站 2022-06-04 15:44:58
...
.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里去,要修改哪些


回复讨论(解决方案)

#当目录存在时不做重写
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]

这样可以了