如何在wordpress htaccess文件中删除外部文件的扩展名?

时间:2013-06-05 22:15:05

标签: php wordpress

目前,我的wordpress .htaccess文件中包含以下内容:

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

# END WordPress

我上传了一个名为contact.php的单独的.php文件,我想重写,以便用户可以通过http://mydomain.com/contact代替http://mydomain.com/contact.php

来访问它

我需要将哪些内容放入我的.htaccess文件中,以便我只能对此一个文件进行重写?

2 个答案:

答案 0 :(得分:2)

只需为重定向添加一行,如下所示:

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

# END WordPress

答案 1 :(得分:1)

你应该在# BEGIN WordPress评论之前加上这个,因为它与WP不相关:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^contact$ /contact.php [L] # /contact rewrite
</IfModule>

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

# END WordPress