我有两个重写规则,按照我添加它们的顺序,它们无法一起工作
第一个从url获取名称,例如
http://myUrl.com/JohnSmith
并转发给:
http://myUrl.com/pages/gf_profile.html?user=JohnSmith
代码是:
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ /pages/gf_profile.html?user=$1 [NC,L]
它本身就可以正常工作。第二个是wordpress,我有网址,例如:
http://myUrl.com/blog/my-blog-post
它使用:
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
在第二部分中,当我尝试第一个URL时,它认为这是一个博客标题,因此无法找到它。
有没有办法同时使用它们?
答案 0 :(得分:1)
尝试:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^([^\.]+)$ /pages/gf_profile.html?user=$1 [NC,L]
我认为你的其他规则都在/blog/
目录中(否则它看起来不会正常工作)。
答案 1 :(得分:0)
<强>答案:强>
感谢@anubhava - 我只是在/ blog /文件夹中创建了一个.htaccess文件,其中包含以下内容,现在所有文件都完美无缺。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
我不确定为什么wordpress不会在安装时添加它,它应该恕我直言 - 希望这可能会帮助那些有类似问题的人。