web - LINUX服务器是怎么解决URL的大小写问题??
怪我咯
怪我咯 2017-04-17 11:04:05
0
5
807

LINUX服务器是区分大小写的,
比如你换成LINUX服务器大写的URL是打不开的,而且对于搜索引擎也不友好

那如何解决这个问题呢,让用户输入大写时,也跳转到小写的URL页面。
尽量减少大写造成的影响。

求具体解决方案。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
刘奇

Reposted from: http://www.ithr.org.cn/blogs/blog1.ph...

Case sensitive, sometimes inconvenient, must be written accurately to access, not very friendly to search engines and users. .
The main reason for this phenomenon is the lack of the spelling module, so it only needs to be loaded in the corresponding system.
1. Debian system
It’s relatively simple under debian system
1. Find speling.load from the path /etc/apache2/mods-available and copy it to the path /etc/apache2/mods-enabled
2. Write the file spelling.conf to the directory /etc/apache2/mods-enabled
The content of speling.conf is very simple. All I wrote is the following line:
CheckSpelling on
3. After adding speling.load and speling.conf to /etc/apache2/mods-enabled, just restart apache
2. CentOS system
It's a little troublesome under centos system.
1. Check whether the system has the module mod_speling.so, path: /etc/httpd/modules; if there is, just pass it directly. If you don’t download it from elsewhere, use it
2. Load this module

  • vi /etc/httpd/conf/httpd.conf

In the module loading area, add the following line:
LoadModule speling_module modules/mod_speling.so
CheckSpelling on
Save changes and exit
3. Restart the httpd service

迷茫

If you are using Apache, you can use RewriteMap in mod_rewrite. Add this:

RewriteRule (.*)$  [NC]
刘奇

Apache can also be used like this: the idea is to write the code into the 404 page (404.php), and then the server will convert all the requested URLs into lowercase. After the conversion, if it can be found, it will jump to a new page, but it still cannot be found. Just return to the homepage.

/**
* @file nofound.php
* @version 1.0
* @author hyperjiang
* @date 2007-07-11
* @brief Try to redirect to correct url.
*/

$url = @$_SERVER['REQUEST_URI'];
if (empty($url)) {
header(”Location: /”);
exit;
}

$newurl = strtolower($url);
if ($url == $newurl) header(”Location: /”);
else header(”Location: $newurl”);
?>

Note: 1. Author of this code: hyperjiang URL: http://hi.baidu.com/frag/blog/item/52...

PS, I have not tested this code.

However, I sincerely recommend that you use lowercase for new URLs, and you can use rewrite for old URLs.

If it is an nginx server, just use perl_set

迷茫

‘Unfriendly to search engines’?
Are you talking about Baidu’s case-insensitive search engine?

刘奇

Always lowercase. Capitalization in URLs is no longer friendly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template