1

我有一个带有页面模板和 1 个变量调用 uid (user id) 的 wordpress 站点,我想将其更改为友好的 url。

http://localhost/forum/edit-profile/?uid=1

http://localhost/forum/edit-profile/1

或者

http://localhost/forum/edit-profile/uid/1

P/S:wordpress 已经有一个 .htaccess 文件,我只想添加一些额外的代码。

我尝试了这些解决方案,但它们不起作用:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forumengine/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forumengine/index.php [L]

RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
</IfModule>
4

1 回答 1

0

将此添加到您的.htaccess规则中

RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]

这将重定向/forum/edit-profile/?uid=1/forum/edit-profile/1和返回。

编辑:(他们应该像wordpress规则一样)

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /forumengine/

  RewriteRule ^index\.php$ - [L]

  RewrieCond %{QUERY_STRING} !no-redir [NC]
  RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
  RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]

  RewriteCond %{REQUEST_FILENAME} !-d # not a dir
  RewriteCond %{REQUEST_FILENAME} !-f # not a file
  RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /forumengine/index.php [L]
</IfModule>
于 2013-08-20T04:09:49.400 回答