.htaccess删除.php并添加尾部斜杠

时间:2014-02-07 11:00:06

标签: php .htaccess mod-rewrite rewrite slash

我正在尝试从我的网址中删除.php并在末尾添加一个尾部斜杠。我已经完成了.php删除工作,但我正在努力让尾随斜线正常工作。

这是我到目前为止所得到的:

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

提前致谢!

2 个答案:

答案 0 :(得分:4)

首先,代码和注释看起来非常熟悉:)

使用此代码:

RewriteEngine On
RewriteBase /

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

# add a trailing slash    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

答案 1 :(得分:0)

for(index=0;index<10;index++)
{
    scanf("%d", ptr);
    printf("%d", *ptr);
    ++ptr;
}