赏金注意:我找到了我的问题使用add_rewrite_rules我的解决方案。我会奖励任何能够以apache RewriteRules格式为我提供相同解决方案的人。如何将字符串转换为slu??
我读过How can I create friendly URLs with .htaccess?但它仍然困难和复杂的我。
我正在运行WordPress多站点,并且我有一个子域网站cp.example.com,我在这个子域上编写了一个php应用程序。
我有一个网站地址,如下所示:
http://cp.example.com/sales.php?id=12345&userid=123456&uid=83hkuhdqhuhd873xsuhdqwiuhdiq
是否有可能对我来说,让用户访问通过网站:
http://cp.example.com/sales/12345/userid/123456/83hkuhdqhuhd873xsuhdqwiuhdiq
如果我是这样做的意愿php仍然能够在值上做$_GET
?
例如$_GET['id']
,$_GET['userid']
和$_GET['uid']
?
我为我的基地使用WordPress,但我正在写应用程序结束,使用不同的表格。
我试图避免使用自定义帖子类型来实现上述目的。
我试过以下。
创建一个模板文件view_sales.php在view_sales.php我需要
$_GET['id']
,$_GET['userid']
和$_GET['uid']
以检索从MySQL信息。在
view_sales.php
我也使用了不同的头文件并且有get_header('sales')
;in header-sales.php我已经添加了从上面的堆栈溢出页面获得的以下代码。
$path_components = explode('/', $_GET['url']); $id=$path_components[0]; $userid=$path_components[1]; $uid=$path_components[2];
我创建了蛞蝓销售新的WP页面所以现在的网站是 http://cp.example.com/sales/?id=123456&userid=123456&token=98917397219372iheu1i
我只有一个
.htacess
网站在我/public_html/example.com
领域,因为它是一个多点,所以我说上面的代码提示我的.htaccess
现在看起来像这样。RewriteEngine On RewriteBase/ RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule^- [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] </IfModule>
没有什么工作的那一刻,还是重定向到难看网址。
编辑:
我已经试过以下
RewriteCond %{HTTP_HOST} !^cp\.example\.com [NC]
RewriteRule ^listing/([a-z0-9]+)$ listing/?action=$1 [L,NC]
RewriteRule ^view/([a-z9-9]+)$ view/?id=$ [L,NC]
我试过的所有上述但没有任何工程不同的变体。
编辑的,我试过
function pa_custom_rules() {
add_rewrite_rule('^/listing/([^/]+)/$', 'index.php?pagename=listing&action=$matches[1]', 'top');
}
add_action('init', 'pa_custom_rules');
印刷重写阵列,我可以看到新规则
[^/listing/([^/]+)/$] => index.php?pagename=listing&action=$matches[1]
访问的index.php的作品,但会add_rewrite_rule方法/列表/测试/失败。它返回404错误。
会打破wordpress多站点? –
@Dave Teu不幸的是我不知道。这取决于wordpress如何确定当前网站的名称。 – Eugeny
我从其他网站上读到关于Rewritecond的内容,所以我添加了以下RewriteCond%{HTTP_HOST}!^ cp。[NC] RewriteCond%{HTTP_HOST} ^(。+?)\。example.com $ [NC] RewriteRule^listing /([a-z0-9] +)$ listing /?action = $ 1 [L,NC]但它一直给我404错误 –