2014-10-22 138 views
0

我总是与.htaccess纠缠在一起,所以希望有人能帮我写一个。 我发现网上的东西相似,我想要什么,但我没有足够的信心 改写自己重写:P漂亮的网址.htaccess

我想这一点:

/foo/ = index.php?a=foo 
/foo/bar/ = index.php?a=foo&b=bar 
etc. up to /foo/bar/baz/cat/dog/ (&e=dog) 

我也希望index.php来不可见,以便/index.php重写为/。

另一件事,我想那里始终是跟随斜线,因此有能力做 ...

/foo/bar/baz/?another=whatever 

我的目录如/图片/我不希望这适用于, 所以我必须为此做一个白名单或是否有某些我可以使用的重定向?

干杯!

+0

你发现你试过的代码是什么? – 2014-10-22 08:25:51

回答

0

您不需要将目录白名单。这就是RewriteConds的用途。

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

它检查以确保它不是一个真正的文件或真正的目录,然后执行RewriteRule。

在你的.htaccess文件中试试下面的这些规则来得到你想要的。

RewriteEngine On 
RewriteCond %{REQUEST_URI} /+[^\.]+$ 
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?a=$1&b=$2&c=$3&d=$4&e=$5&%{QUERY_STRING} [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?a=$1&b=$2&c=$3&d=$4&%{QUERY_STRING} [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/([^/]+) index.php?a=$1&b=$2&c=$3&%{QUERY_STRING} [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+) index.php?a=$1&b=$2&%{QUERY_STRING} [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+) index.php?a=$1&%{QUERY_STRING} [L] 
+0

除了重定向index.php之外,我已经从另一个教程中获得了很多: https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html – Varrick 2014-10-22 10:15:23