Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从wordpress站点将.htaccess中的动态URL重写为静态URL_Wordpress_.htaccess_Url Rewriting_Dynamic Url_Wp Rewrite - Fatal编程技术网

从wordpress站点将.htaccess中的动态URL重写为静态URL

从wordpress站点将.htaccess中的动态URL重写为静态URL,wordpress,.htaccess,url-rewriting,dynamic-url,wp-rewrite,Wordpress,.htaccess,Url Rewriting,Dynamic Url,Wp Rewrite,我想重写动态url: /location.php?c=city&s=state 要保持静态: /location-city-state 在同一域的同一文件夹中。我试过下面的代码: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteRule location-(.*)-(.*) location.php?c=$1&s=$2 </IfModule>

我想重写动态url:

/location.php?c=city&s=state
要保持静态:

/location-city-state
在同一域的同一文件夹中。我试过下面的代码:

<IfModule mod_rewrite.c>  
Options +FollowSymLinks  
RewriteEngine on  
RewriteRule location-(.*)-(.*) location.php?c=$1&s=$2  
</IfModule>

选项+FollowSymLinks
重新启动发动机
重写规则位置-(.*)-(.*)location.php?c=$1&s=$2
但问题是它是一个Wordpress网站,在我的例子中,它与Wordpress.htaccess不兼容。当我去的位置/城市州,它给我404,我如何才能解决这个问题

以下是.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> 
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

我已经尝试在wordpress代码开始之前和之后添加重写代码,但仍然不起作用。

你必须使用wp重写api,因为我认为这不是htaccess问题。谢谢你,你是救命恩人,我补充道:
函数自定义重写规则(){添加重写规则('^([^/]*)-([^/]*)-location/?,'location.php?c=$1&s=$2','top');}添加操作('init','custom_rewrite_rule',10,0)
到functions.php,它就像一个符咒。对于其他有相同问题的人,请访问: