我在stack上读到了几个类似的主题,但没有一个答案能起到作用,所以:
我开始使用Wordpress并创建了我的第一个主题。我已经在localhost/first-wp/
和localhost/first-wp/wp-content/themes/first-theme/
中放置了WP,我有几个文件,如index.php、login.php或register.php
现在,我想通过漂亮的permalink访问这些文件,例如localhost/first-wp/login
或localhost/first-wp/register
。
我在localhost/first-wp/
中创建了.htaccess文件,并在其中放置了以下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /first-wp/
RewriteRule ^index'.php$ - [L]
RewriteRule ^login? /first-wp/wp-content/themes/first-theme/login.php [QSA,L]
RewriteRule ^register? /first-wp/wp-content/themes/first-theme/register.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /first-wp/index.php [L]
</IfModule>
但问题是,当我输入例如localhost/first-wp/login
时,我会得到错误:Call undefined function 'my_simple_func()' in /Applications/XAMPP/xamppfiles/htdocs/first-wp/wp-content/themes/first-theme/login.php
。当然,这个函数位于我的主题目录中的functions.php中。
我该如何解决这个问题,输入漂亮的永久链接,而不会得到这个错误?谢谢你的建议。
您正在使用RewriteBase复制您的目录。
尝试:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /first-wp/
RewriteRule ^index'.php$ - [L]
RewriteRule ^login? wp-content/themes/first-theme/login.php [QSA,L]
RewriteRule ^register? wp-content/themes/first-theme/register.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>