mod_rewrite规则不起作用(将参数从一个url传递到另一个url)

时间:2016-07-04 05:29:52

标签: php apache .htaccess mod-rewrite

无论我如何修改此声明,无论如何都无法让它发挥作用。例如,我想从/ path /更改为/ class / Ad234Db更改为/ path / to / class?code = Ad234Db。以下都不起作用:

RewriteRule ^/?path/to/class/([-a-zA-Z0-9]+)$ /path/to/class.php?code=$1 [L]

RewriteRule ^/path/to/class/([-a-zA-Z0-9]+)$ /path/to/class.php?code=$1 [L]

RewriteRule ^path/to/class/([-a-zA-Z0-9]+)$ /path/to/class.php?code=$1 [L]

此外,下面的重写语句仍然有效:

RewriteRule ^([^\.]+)$ $1.php [NC,L]

1 个答案:

答案 0 :(得分:1)

尝试:

RewriteRule ^path/to/class/([A-Z0-9]+)/?$ /path/to/class.php?code=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+)/?$ $1.php [L]