我想删除问号和放大器; PHP扩展的URL使用.htaccess中的 [英] I want to remove question mark & .php extension from the url using .htaccess

查看:232
本文介绍了我想删除问号和放大器; PHP扩展的URL使用.htaccess中的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在.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} ^GET\s([^.]+)\.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} ^GET\s([^.]+)\.php\s [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]

这篇关于我想删除问号和放大器; PHP扩展的URL使用.htaccess中的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆