我最近使用以下 htaccess 将带有参数的 url 更改为更具可读性的 url:
RewriteRule ^page/([A-Za-z0-9-+_\s]+)$ /index.php?n=$1 [L]
RewriteRule ^category/([A-Za-z0-9-+_\s]+)/([0-9]+)$ /index.php?p=$1&b=$2 [L]
我相信这会导致搜索引擎上出现重复内容的问题,因为 index.php url 和 domain.com/page/url 都将被编入索引。
如果对 domain.com/page/1
的调用被重定向到 index.php?n=1
我该如何重定向对 index.php 的请求? php
到 domain.com/page/
??
我这样做的尝试是给我一个 404 代码,将我发送到 domain2。
#RewriteCond %{QUERY_STRING} ^n=([A-Za-z0-9]+)$ [NC]
#RewriteRule ^index\.php$ http://domain.com/page/? [R=301,L]
htaccess
IndexIgnore *
ErrorDocument 404 http://domain2.com
#REDIRECTS
Redirect 301 /keyword.php http://domain.com
Redirect 301 /inc/keyword.php http://domain.com
Options +FollowSymlinks
RewriteEngine on
#Redirect all pages in a folder to a single URL
RewriteRule ^test/(.*)$ http://domain.com [L,R=301]
# HTTP HOST, escape . and start string with ^
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,NC]
RewriteCond %{QUERY_STRING} ^p=h&m=([A-Za-z]+)&y=([0-9]+)$ [NC]
RewriteRule ^index\.php$ http://domain.com? [R=301,L]
#RewriteCond %{QUERY_STRING} ^n=([A-Za-z0-9]+)$ [NC]
#RewriteRule ^index\.php$ http://domain.com/page/? [R=301,L]
RewriteRule ^page/([A-Za-z0-9-+_\s]+)$ /index.php?n=$1 [L]
RewriteRule ^category/([A-Za-z0-9-+_\s]+)/([0-9]+)$ /index.php?p=$1&b=$2 [L]
最佳答案
代替您评论的 301 规则试试这个:
RewriteCond %{THE_REQUEST} /index\.php\?n=([^\s&]+)&y=([^\s&]+) [NC]
RewriteRule ^ /page/%1/%2? [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\?n=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=301,L]
关于apache - 将带有参数的 url 重定向到可读的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23389126/