can not sitemap after url rewrite

筅森魡賤 提交于 2019-12-11 18:19:29

问题


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!


回答1:


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]



回答2:


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.



来源:https://stackoverflow.com/questions/18865601/can-not-sitemap-after-url-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!