can not sitemap after url rewrite

2019-09-06 01:45发布

I have written a rewrite rule in the .htaccess file for my website page:

RewriteRule ^nice_url/$  ?p_action=user_profile&post_author=45 [L]

The full link is: "http://www.example.co.il/nice_url/" it works perfect.

BUT, when I try to create a sitemap (e.g. with http://www.web-site-map.com/), I have an indication that the link "http://www.example.co.il/nice_url/" is broken.

Why?

The link is working fine. Why is it indicated as broken?

Thanks!

2条回答
Animai°情兽
2楼-- · 2019-09-06 01:46

Seems that I found the problem:

I have a main .htaccess file that redirects to 3 different folders. Each folder is for a different website (all in the same host).

One of the websites is in WP. The rewrite happens well.

BUT, when I try to generate a sitemap - the wp returns a 404 for the sitemap generator and thats why I get an error.

solution: I'll probably try to rewrite from the php and not from the htaccess.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-09-06 02:05

You can just add another rule to externally redirect long URL to nice URL like this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?p_action=user_profile&post_author=45\s [NC]
RewriteRule ^ nice_url? [R=301,L]

UPDATE: Alright I checked that sitemap generator is putting & instead of & in generated URLs.

You need to add this additional rule to handle this:

# convert & to &
RewriteCond %{QUERY_STRING} ^(.*)&(.*)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1&%2 [L,R,NE]
查看更多
登录 后发表回答