通过htaccess重写URL

时间:2014-07-24 16:44:11

标签: .htaccess mod-rewrite

我要更改此网址:http://localhost:8888/finance/schedule/?location=new_yorkhttp://localhost:8888/finance/schedule/location/new_york 它是一个wordpress网站,我的htaccess代码是:

RewriteRule ^schedule/location/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\$ schedule/?location=$1

但似乎没有任何事情发生,请建议。

整个htaccess文件代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /finance/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /finance/index.php [L]

RewriteRule ^schedule/location/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\$ schedule/?location=$1

</IfModule>

1 个答案:

答案 0 :(得分:0)

这条线阻止它达到你后来的规则:

RewriteRule . /finance/index.php [L]

[L]表示&#34;最后,&#34;如在&#34;这是最后一个匹配的规则。&#34;

并且\$会查找文字$,而不是字符串的结尾。

您的规则中还有两个匹配的组。

你需要这样的东西,而不是(完全未经测试):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /finance/
RewriteRule ^index\.php$ - [L]

RewriteRule ^schedule/location/([a-zA-Z0-9_-]+?)/?$ /wp-content/themes/financeinstitute/page_schedule.php/?location=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /finance/index.php [L,QSA]

</IfModule>