【发布时间】:2015-12-19 20:39:31
【问题描述】:
首先:我过去有一个错误的策略,在我的 url 中包含无用/无意义的“seo_url=keyword”元素,现在我想在 URL 中的任何位置删除它,并在没有该元素的情况下重写我的 URL。 (301 重定向)
第二:有时一个元素或某些元素是空的,例如“location=”或“location=&select=”,如果它们在 URL 中的任何位置为空,我会删除这些元素,并在没有这些元素的情况下重写我的 URL。 (301 重定向)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC,OR]
RewriteCond %{REQUEST_FILENAME} -l [NC]
RewriteRule .* - [L]
RewriteRule (.*)/$ /?countrySelect=$1
RewriteRule (.*)/+/(.*)-(.*)\.html$ search-products.php?countrySelect=$1&productselect=$2&submit=1
RewriteRule (.*)/tag/(.*) search-products.php?countrySelect=$1&keyword=$2
RewriteRule (.*)/(.*)/(.*)-(.*)\.html$ search-products.php?productLocation=$2&countrySelect=$1&productselect=$3&submit=1
RewriteRule (.*)/(.*)_(.*)\.html$ detail.php?name=$2&id=$3&detail=true&countrySelect=$1</IfModule>
【问题讨论】:
-
请显示您当前使用的代码。
-
按要求添加代码
-
您仅在内部使用这些链接(用于公开使用漂亮链接)。我不明白您为什么要对更正的链接进行重定向?
-
不,我公开使用它们。我的代码中有什么让你这么想吗?
-
你从漂亮的链接重写...
标签: php .htaccess mod-rewrite url-rewriting