htaccess的我如何能实现这两个"个性化网址"和"没有扩展名QUOT; [英] .htaccess how can I implement both "vanity url" and "no extension"

查看:169
本文介绍了htaccess的我如何能实现这两个"个性化网址"和"没有扩展名QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是从stackoverflow.com/q/8583856 htaccess的 -

I'm using htaccess from stackoverflow.com/q/8583856 -

RewriteEngine on
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.mysite.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.mysite.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://www.mysite.com/profile.php?u=$1 [NC]

Everything works great unless I type www.mysite.com into address bar -    
returns mysite.com/profile?u=index.html.var  
which errors "Unknown column index.html.var in where clause"  

任何人都知道如何得到这个去mysite.com/index~~V呢?

Anyone know how to get this to go to mysite.com/index instead?

推荐答案

尝试添加一个条件,以检查是否路径为空(即根)

try adding a condition to check if the path is empty (i.e. root)

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond $0 ^$
RewriteRule .* - [L]

这篇关于htaccess的我如何能实现这两个"个性化网址"和"没有扩展名QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆