Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://m.mysite.com/$1 [R=301,L]
AddHandler application/x-httpd-php5 .html .htm .txt .php
my .htaccess使用主"files.php"来处理所有请求。在我的files。php中,我有一些代码,其中包括href,如下所示:
/people/john
->当一个人点击这个,它应该去:people.php?q=john
然而,当人们点击这个/people/john
时,我的。htaccess不重定向。顺便说一句,url应该总是说/people/john
而不是people.php?q=john
,即使这是幕后发生的事情。
只是想说,我有
/city/newyork --> city.php?q=newyork
/country/australia --> country.php?q=australia
我一直在努力和搜索这里找到确切的,但仍然没有运气。我感谢所有的回应。
根据你的例子,你有这样的url:
/city/newyork, where city is the php file to call with parameter newyork
如果这是你想要的,试试这个:+ FollowSymLinks选项RewriteEngine
# Rewrite /city/newyork to city.php?q=newyork
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L]
# Rewrite all urls without a second / to files.php?q=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://m.mysite.com/$1 [R=301,L]
AddHandler application/x-httpd-php5 .html .htm .txt .php
这是我使用的CodeIgniter(支持非常深的a/b/c/d/e/f/g)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ files.php?/$1 [L]
一行一行地写着
-将重写引擎打开
-使用web_root(如果你在子文件夹中,它可能不适合你)
-如果url不是一个存在的文件
-并且url不是一个已经存在的目录
-将参数映射到files.php
刚刚意识到你正在使用Files.php…真奇怪,为了保持一致性,应该把它叫做index,如果它是所有东西都应该经过的,或者做一个索引,把文件夹/files/*经过index.php?
希望能有所帮助
你想让它变成动态的吗?我的意思是,/$anything1/$anything2
将被重新映射到/$anything1.php?=$anything2
:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /%1.php?q=%2
或者如果上面的代码不起作用,试试这个:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) http://%{HTTP_HOST}/%1.php?q=%2 [P]
Faa,我做了你说的,下面是我的服务器变量,我认为正确的变量应该是下面说的"应该是这个:"。
["QUERY_STRING"]=>
string(17) "q=city/newyork"
["REDIRECT_QUERY_STRING"]=>
string(17) "q=city/newyork"
["REDIRECT_STATUS"]=>
string(3) "200"
["REDIRECT_URL"]=>
string(16) "/city/newyork"
["REQUEST_URI"]=>
string(16) "/city/newyork"
["SCRIPT_FILENAME"]=>
string(30) "/home/mywebsite/myfiles.php"
["SCRIPT_NAME"]=>
string(14) "/myfiles.php"
["PHP_SELF"]=>
string(14) "/myfiles.php"
["argv"]=>
array(1) {
[0]=>
string(17) "q=city/newyork"
}
should be this:
["QUERY_STRING"]=>
string(16) "q=newyork"
["REDIRECT_QUERY_STRING"]=>
string(16) "q=newyork"
["REDIRECT_STATUS"]=>
string(3) "200"
["REDIRECT_URL"]=>
string(25) "/city/newyork"
["REQUEST_URI"]=>
string(25) "/city/newyork"
["SCRIPT_FILENAME"]=>
string(30) "/home/mywebsite/city.php"
["SCRIPT_NAME"]=>
string(14) "/city.php"
["PHP_SELF"]=>
string(14) "/city.php"
["argv"]=>
array(1) {
[0]=>
string(16) "q=newyork"
}