htaccess的我如何能实现这两个"个性化网址"和"没有扩展名QUOT;这两个、扩展名、网址、htaccess

2023-09-02 01:09:22 作者:国产祖宗

我使用的是从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]