du6029076877 2016-09-13 07:18
浏览 53

自定义PHP中的Wordpress htaccess

I am currently creating a new website which uses custom PHP code, but i am retrieving Wordpress posts too from a remote wordpress.

In my root folder (as wordpress does), i have the default wordpress .htaccess file:

# 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 also have a index.php file which gives me the posts from WP:

<?php
// Include the wp-load'er
include('wp/wp-load.php');


// Get the last 10 posts
$recent_posts = wp_get_recent_posts(array(
    'numberposts' => 10,
    'post_status' => 'publish'
));

...
?>

In my project i also have other custom php files like search.php, detail.php etc.

All Wordpress posts links are formatted using slugs like: www.mywebsite.com/my-post/

The question is, how can I change .htaccess file in order to pass index.php a slug parameter when the URL is not a .php file?. (Like index.php?slug=my-post)

Thanks.

  • 写回答

2条回答 默认 最新

  • dscc90150010 2016-09-13 07:31
    关注

    You can try something like that. I hope that help you.

    RewriteEngine On
    RewriteCond %{REQUEST_URI}  ^/index\.php$
    RewriteCond %{QUERY_STRING} ^slug=(.*)$
    RewriteRule ^(.*)$ http://www.mywebsite.com/page/%1.html [R=302,L]
    
    # 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 WordPres
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机数字电压表电路组成及框图
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line