快捷方式 URL 重定向
ShortCut URL Redirect
开门见山。
我有这个URL:http://example.com/?open=encyclopedia&letter=s&term=storm and I want this shortcut URL - http://example.com/storm - to redirect to the first URL: http://example.com/?open=encyclopedia&letter=s&term=storm
我有大约 1.000 个百科全书术语,我希望此重定向适用于输入的每个术语。例如:如果访问者输入 http://example.com/Storm to automatically be redirected to the page here: http://example.com/?open=encyclopedia&letter=s&term=storm OR http://example.com/Dried_Plant to http://example.com/?open=encyclopedia&letter=d&term=dried+plant
如果可能的话,我更喜欢一些 htaccess 解决方案。
如果没有,就给你能给的。
我没有这方面的示例代码,因为我不知道从哪里开始。
我建议您将其全部重定向到您的页面 encyclopedia
。然后用 php 考虑你可以用它做什么(比如找到第一个字母或用 _ 或其他改变)
您可以使用:
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ encyclopedia?term=%{REQUEST_URI} [NE,L]
首字母正确 (letter=
),将最后一行更改为:
RewriteRule ^(.) encyclopedia?letter=&term=%{REQUEST_URI} [NE,L]
@Croises 如果您的 link 看起来像以下
,那么答案很好
mysite.com/?open=encyclopedia&letter=s&term=/storm
REQUEST_URI
正在添加尾部斜杠。你的 link 没有:
mysite.com/?open=encyclopedia&letter=s&term=storm
我想这就是您要找的东西
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .(.+)$
RewriteRule ^(.) ?open=encyclopedia&letter=&letter=%1 [NC,L]
开门见山。
我有这个URL:http://example.com/?open=encyclopedia&letter=s&term=storm and I want this shortcut URL - http://example.com/storm - to redirect to the first URL: http://example.com/?open=encyclopedia&letter=s&term=storm
我有大约 1.000 个百科全书术语,我希望此重定向适用于输入的每个术语。例如:如果访问者输入 http://example.com/Storm to automatically be redirected to the page here: http://example.com/?open=encyclopedia&letter=s&term=storm OR http://example.com/Dried_Plant to http://example.com/?open=encyclopedia&letter=d&term=dried+plant
如果可能的话,我更喜欢一些 htaccess 解决方案。 如果没有,就给你能给的。 我没有这方面的示例代码,因为我不知道从哪里开始。
我建议您将其全部重定向到您的页面 encyclopedia
。然后用 php 考虑你可以用它做什么(比如找到第一个字母或用 _ 或其他改变)
您可以使用:
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ encyclopedia?term=%{REQUEST_URI} [NE,L]
首字母正确 (letter=
),将最后一行更改为:
RewriteRule ^(.) encyclopedia?letter=&term=%{REQUEST_URI} [NE,L]
@Croises 如果您的 link 看起来像以下
,那么答案很好mysite.com/?open=encyclopedia&letter=s&term=/storm
REQUEST_URI
正在添加尾部斜杠。你的 link 没有:
mysite.com/?open=encyclopedia&letter=s&term=storm
我想这就是您要找的东西
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .(.+)$
RewriteRule ^(.) ?open=encyclopedia&letter=&letter=%1 [NC,L]