Apache 如何排除GET变量并将其重写为重定向url
我想将Apache 如何排除GET变量并将其重写为重定向url,apache,.htaccess,url,mod-rewrite,url-rewriting,Apache,.htaccess,Url,Mod Rewrite,Url Rewriting,我想将test.com/folder/create重定向到test.com/folder/create(.php) 但是/folder/之后的任何内容都会被视为$\u GET[]变量,如下所示 RewriteCond %{REQUEST_URI} !^/folder/index\.php$ [NC] RewriteRule ^folder/([^/]*)$ /folder/index.php?type=$1 我试过了 RewriteCond %{REQUEST_URI} !^/fold
test.com/folder/create
重定向到test.com/folder/create(.php)
但是/folder/
之后的任何内容都会被视为$\u GET[]
变量,如下所示
RewriteCond %{REQUEST_URI} !^/folder/index\.php$ [NC]
RewriteRule ^folder/([^/]*)$ /folder/index.php?type=$1
我试过了
RewriteCond %{REQUEST_URI} !^/folder/create\.php$ [NC]
RewriteRule ^folder/create$ /folder/create.php
但是运气不好(错误500),有人能给我指出正确的方向,告诉我怎么可能做到这一点吗
编辑:仍在尝试在网上搜索答案,运气不好
编辑:小编辑,
现行代码
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^item\.php$
RewriteRule ^([^/]+)/?$ index.php?type=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?type=$1&page=$2 [L,QSA]
RewriteRule ^item/([^/]+)/?$ item.php?id=$1 [L,QSA]
RewriteRule ^item/([^/]+)/([^/]+)/?$ item.php?id=$1&page=$2 [L,QSA]
重写基是/folder/
/文件夹/项目工作并重定向到item.php
/文件夹/item/2出现500错误,有什么建议吗?请尝试以下选项:
Options -MultiViews
RewriteRule ^folder/create$ folder/create.php
您可以在
文件夹/.htaccess
中使用这些规则(不在站点root.htaccess中):
猜猜看,第二个没有重写条件,只有规则?@rtfm nope don't work您缺少重写规则中的
/
。尝试RewriteRule^/folder/create$/folder/create.php
。因为^folder
的意思是以folder开头,但它以/folder
开头。mod rewrite在我运行的每台服务器上的工作方式似乎都不一样,我只是尝试了无数次,直到找到它为止lucky@Nic3500刚才试过了,,没有工作谢谢你的回答我怎么能做像这样的事情呢?RewriteRule.+index.php?type=$0&page=$1[L,QSA]
Normal-/folder/index.php?type=$1
| With page/folder/index.php?type=$1&page=$2
所以类似于test.com/folder/type/page
的东西只有最后一个问题,行RewriteCond%{REQUEST_FILENAME}.php-f RewriteRule^(+?)/?$$1.php[L]
允许我转到/folder/item
,但我添加了一个RewriteCond来尝试允许我转到folder/item/x
,但我一直收到500个错误。有什么想法吗?让我们知道问题是什么吗/folder/item(.php)
可以工作,但/folder/item/test
不能@anubhava
DirectoryIndex index.php
RewriteEngine On
RewriteBase /folder/
# append .php extension to every request that has a corresponding .php file
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# rewrite all non-existing files and folders to index,php?type=...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ index.php?type=$0 [L,QSA]