使用wordpress在.htaccess中重写URL

时间:2018-01-09 12:03:34

标签: wordpress .htaccess url url-rewriting

我想在名为https://greennutritionguides.dk的网站上更改这些网址。我发现这可以通过在.htaccess文件中重写来完成。然而到目前为止,我已经在堆栈和其他网站上找到了我不知道的东西。

我想要更改这些网址:

greennutritionguides.dk/shop-4/ to greennutritionguides.dk/shop

和greennutritionguides.dk/services-2/到greennutritionguides.dk/service

greennutritionguides.dk/member-receipes-2/ to greennutritionguides.dk/opskrifter

此网站是一个wordpress网站,并且有一个.htaccess文件,如下所示:

## EXPIRES CACHING ##
#<IfModule mod_expires.c>
#ExpiresActive On
#ExpiresByType image/jpg "access 1 year"
#ExpiresByType image/jpeg "access 1 year"
#ExpiresByType image/gif "access 1 year"
#ExpiresByType image/png "access 1 year"
#ExpiresByType text/css "access 1 month"
#ExpiresByType text/html "access 1 month"
#ExpiresByType application/pdf "access 1 month"
#ExpiresByType text/x-javascript "access 1 month"
#ExpiresByType application/x-shockwave-flash "access 1 month"
#ExpiresByType image/x-icon "access 1 year"
#ExpiresDefault "access 1 month"
#</IfModule>
## EXPIRES CACHING ##
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule    ^shop-4/$    shop   

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

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

2 个答案:

答案 0 :(得分:0)

将以下代码放在.htaccess的开头

之前
Redirect 301 https://greennutritionguides.dk/shop-4/ https://greennutritionguides.dk/shop
Redirect 301 https://greennutritionguides.dk/services-2/ https://greennutritionguides.dk/service
Redirect 301 https://greennutritionguides.dk/member-receipes-2/ https://greennutritionguides.dk/opskrifter

答案 1 :(得分:0)

请按照重定向网址的步骤进行操作

步骤1:备份.htaccess文件

步骤2:使用以下代码替换整个.htaccess文件并保存。

#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^shop-4(/.*)?$ https://greennutritionguides.dk/shop/ [L,R=301,NC]
RewriteRule ^services-2(/.*)?$ https://greennutritionguides.dk/service/ [L,R=301,NC]
RewriteRule ^member-receipes-2(/.*)?$ https://greennutritionguides.dk/opskrifter [L,R=301,NC]
RewriteBase /gdk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /gdk/index.php [L]
</IfModule>
#END WordPress

步骤3:清除浏览器的缓存,然后进行检查。

您也可以参考301 redirect not working via .htaccess within WordPress