我有在.htaccess重定向URL的一个问题。我想删除的.php和放大器;从URL问号。
例如: www.example.com/test.php?id=12 为 www.example.com/test/12 需要这样的格式
我试图用这个code在我的.htaccess
选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /
##不要触摸/论坛的URI
重写规则^论坛/ - [L,NC]
##隐藏PHP扩展片段
#要外部重定向/dir/foo.php到/ DIR /富
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} S([^。] +)。PHP [NC]
重写规则^%1 [R,L]
#在内部前进/ DIR /富到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^(。*?)/?$ $ 1.PHP [L]
这code只是删除了PHP扩展的URL。还需要删除问号。
解决方案这code似乎是从我的答案之一:)
这个替换您的code:
选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /
##不要触摸/论坛的URI
重写规则^论坛/ - [L,NC]
##隐藏PHP扩展片段
#要外部重定向/dir/foo.php?id=123到/ DIR /富
?的RewriteCond%{THE_REQUEST} ^ GET S([^] +) PHP ID =([^&放大器; S] +)[NC]
重写规则^%1 /%2? [R,L]
#在内部前进/ DIR /富/ 12 /dir/foo.php?id=12
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^(。+?)/([^ /] +)/ $ $ 1.PHP?ID = $ 2 [L,QSA]
#要外部重定向/dir/foo.php到/ DIR /富
的RewriteCond%{THE_REQUEST} ^ GET S([^。] +)。PHP S [NC]
重写规则^%1 [R,L]
#在内部前进/ DIR /富到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
的RewriteCond%{QUERY_STRING} ^ $
重写规则^(。*?)/?$ $ 1.PHP [L]
I have a problem with redirect URL in .htaccess. I want to remove .php & question marks from the URL.
For Example: www.example.com/test.php?id=12 to www.example.com/test/12 need like this format.
I tried using this code in my .htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,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 %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
This code just removes the .php extension from the URL. Also need to remove the question mark.
解决方案That code appears to be from one of my answers :)
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php?id=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GETs([^.]+).php?id=([^&s]+) [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?id=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?id=$2 [L,QSA]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^GETs([^.]+).phps [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*?)/?$ $1.php [L]