简体   繁体   English

WordPress和.htaccess

[英]WordPress & .htaccess

I have a website under WordPress where I've created a new page www.foo.com/section/ 我在WordPress下有一个网站,在那里我创建了一个新页面www.foo.com/section/

The idea is to create a permalink like www.foo.com/param1/type/param2 and with .htaccess use a rewrite rule to: www.foo.com/section/?var1=param1&var2=param2&var3=type 这个想法是创建一个类似www.foo.com/param1/type/param2的永久链接,并使用.htaccess使用重写规则来:www.foo.com/section/?var1=param1&var2=param2&var3=type

RewriteEngine on
Options +FollowSymlinks
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2

I got it working in my old web but in the WordPress crashes. 我可以在旧网络上运行它,但可以在WordPress中崩溃。

#My rules -> copy&paste
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2
# 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        

I've only got a beautiful WordPress' 404 page 我只有一个漂亮的WordPress'404页面

I've read several questions here but no one helps me. 我在这里读了几个问题,但是没人帮我。

Thanks for your time and best regards, 感谢您的宝贵时间和最诚挚的问候,

R. R.

13 Jan 一月13

I've created a simple test to check it. 我创建了一个简单的测试来检查它。

The new structure works with a test case without problems: 新结构可以在没有问题的情况下使用测试用例:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^lol/$ project/ [L] #Rule 1
RewriteRule ^foo/$ test/ [L] #Rule 2

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
  1. Rule 1 , I've created a subfolder in WordPress root, named "project" with an index.php echoing "Hi dad" and when type www.foo.com/lol/ it loads that script and echoes the word. 规则1 ,我在WordPress根目录中创建了一个子文件夹,名为“ project”,带有index.php并回显“ Hi dad”,当键入www.foo.com/lol/时,它将加载该脚本并回显该单词。
  2. Rule 2 , I've created a new WordPress page, www.foo.com/test/ with a simple string to show, but when I write www.foo.com/foo/ it gives me error 404. It seems that the redirection to a wp pages doesn't works as I expected. 规则2 ,我创建了一个新的WordPress页面www.foo.com/test/,其中显示了一个简单的字符串,但是当我编写www.foo.com/foo/时,它给了我错误404。似乎重定向到wp页面无法正常工作。

Disclaimer: Of course www.foo.com/test/ 免责声明:当然是www.foo.com/test/

Now I'm stucked. 现在我被困住了。

Thanks for your previous responses and future help. 感谢您之前的回复和将来的帮助。

Best regards, 最好的祝福,

R. R.

14 Jan 一月14

I have new news :) 我有新消息:)

The new .htaccess that works is: 有效的新.htaccess是:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^([a-z0-9_\s-.()&]+)/alternator/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=A [L]
RewriteRule ^([a-z0-9_\s-.()&]+)/starter_motor/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=M [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Instead redirect to "elecfinder/" in the .htaccess I'm pointing to "?page_id=554", at least it doesn't gives me error 440 而是重定向到.htaccess中的“ elecfinder /”,我指向“?page_id = 554”,至少它没有给我错误440

I'm working on an alternator and starter motors web. 我正在研究交流发电机和起动电动机的网络。

I have a URL that is http://www.elecfinder.com/hitachi/starter_motor/s114850 that really is http://www.elecfinder.com/info/?supplier=hitachi&ref_num=M&reference=s114850 , here I load the reference info. 我有一个网址http://www.elecfinder.com/hitachi/starter_motor/s114850 ,实际上是http://www.elecfinder.com/info/?supplier=hitachi&ref_num=M&reference=s114850 ,在这里我加载了参考信息。

http://wp.elecfinder.com/elecfinder/?reference=s114850&supplier=hitachi&ref_type=M is that web in wp, so my idea is to redirect http://wp.elecfinder.com/hitachi/starter_motor/s114850/ to this. http://wp.elecfinder.com/elecfinder/?reference=s114850&supplier=hitachi&ref_type=M是wp中的那个网站,所以我的想法是将http://wp.elecfinder.com/hitachi/starter_motor/s114850/重定向到此。

Now I'm able to redirect http://wp.elecfinder.com/hitachi/starter_motor/s114850 to http://wp.elecfinder.com/elecfinder/?page_id=554&supplier=hitachi&ref_num=M&reference=s114850 but there are 2 problems: 现在,我可以将http://wp.elecfinder.com/hitachi/starter_motor/s114850重定向到http://wp.elecfinder.com/elecfinder/?page_id=554&supplier=hitachi&ref_num=M&reference=s114850,但是有2个问题:

  1. It changes the url to http://wp.elecfinder.com/elecfinder/ instead maintain wp.elecfinder.com/hitachi/starter_motor/s114850 它将网址更改为http://wp.elecfinder.com/elecfinder/,而是维护wp.elecfinder.com/hitachi/starter_motor/s114850
  2. Misses the GET parameters "reference","supplier" and "ref_type" 缺少GET参数“参考”,“供应商”和“ ref_type”

Thanks for your time. 谢谢你的时间。

Best regards, 最好的祝福,

R. R.

Try the following: 请尝试以下操作:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^([a-z0-9_\s-.()&]+)/(section1|section2)/([a-z0-9]+)$ section/?var1=$1&var2=$3&var3=$2 [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Always put your rules after RewriteEngine on . 始终将规则放在RewriteEngine之后。 And, in this case (WordPress), be sure to put your rules before WordPress' rule (it is here to redirect everything to index.php because WordPress has a front controller and it manages rewriting itself). 并且,在这种情况下(WordPress),请确保将规则放在WordPress的规则之前 (此处是将所有内容重定向到index.php的原因,因为WordPress具有前端控制器并且可以自行重写)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM