目前,我的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文件中,以便我只能对此一个文件进行重写?
答案 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