2011-10-19 26 views
2

我试图让我的网址看在我的网站上特定的子目录漂亮通过重写改变:
www.example.com/sub/file/{some_number}/内部 到:
www.example.com/sub/file.php?var={some_number}
我不断收到404 。 我使用.htaccess文件看起来像这样已经开始转移我的网站php扩展:的.htaccess URL重写与变量

RewriteEngine on 
# 
## Internally rewrite extensionless file requests to .php files ## 
# 
# If the requested URI does not contain a period in the final path-part 
RewriteCond %{REQUEST_URI} !(\.[^./]+)$ 
# and if it does not exist as a directory 
RewriteCond %{REQUEST_FILENAME} !-d 
# and if it does not exist as a file 
RewriteCond %{REQUEST_FILENAME} !-f 
# then add .php to get the actual filename 
RewriteRule (.*) /$1.php [L] 
# 
## Externally redirect clients directly requesting .html page URIs to extensionless URIs 
# 
# If client request header contains html file extension 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP 
# externally redirect to extensionless URI 
RewriteRule ^(.+)\.html$ http://www.dirtycoffee.com/$1 [R=301,L] 

# If client request header contains php file extension 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP 
# externally redirect to extensionless URI 
RewriteRule ^(.+)\.php$ http://www.dirtycoffee.com/$1 [R=301,L] 

我现在的尝试是在像顶部添加一行:

#Subdirectory rewrite: 
RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L] # Handle requests for file 

我知道我必须有冲突的规则,但我认为[L]会停止,如果新规则被应用。

回答

1

相反的:

RewriteRule ^sub/file/([0-9]+)/?$ sub/file?num=$1 [L] 

尝试:

RewriteRule ^sub/file/([0-9]+)/?$ /sub/file.php?num=$1 [L] 

你是正确的,[L]将停止处理规则,但是这也意味着你不能消除,因为php扩展规则是低于这一个。另请注意主导斜线。

+0

这样做!非常感谢!我一直盯着这种方式太久了。另外(Google员工的注意事项)不得不将链接更新到我的CSS表格,因为该页面将其视为目录更改。 – chris