如何通过删除查询字符串并使网址清理来帮助.htaccess文件清理我的网址?

时间:2014-01-12 09:38:11

标签: apache .htaccess mod-rewrite rewrite

我有这样的网址,我想从

清理我的网址

http://www.125books.com/move-other-bk?file=Advanced.C%20sharp%20.Programming.pdf

http://www.125books.com/move-other-bk/file/Advanced.C%20sharp%20.Programming.pdf

贝洛是我的htaccess文件

Options +FollowSymLinks -MultiViews
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 %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

1 个答案:

答案 0 :(得分:0)

让您的代码如下:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(move-other-bk)\?(file)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^(move-other-bk)/(file)/([^/.]+)/?$ /$1?$2=$3 [L,QSA,NC]

## 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 %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]