虚荣的网址没有在Apache尾随斜杠 [英] Vanity URLs without trailing slashes on Apache

查看:269
本文介绍了虚荣的网址没有在Apache尾随斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下code重写所有URL在我们的网站上/配置文件/目录从 example.com/profiles/name / example.com/name / ,但我们也想删除尾随斜线进一步简化产生的URL到prettier example.com/name - 就像现代社会媒体

The code below rewrites all URLs in the /profiles/ directory on our site from example.com/profiles/name/ to example.com/name/, but we'd also like to remove the trailing slashes to further simplify the resulting URLs to the prettier example.com/name -- just like on modern social media.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profiles/$1 [NC,L]

如何才能做到这一点(和安全进行)?我们看到的几个绊倒后的解决方案,如果合并可能可以工作,但在我们网站上的所有配置文件目前有自己的物理目录,而不是通过一个脚本组装的飞行。

How can this be done (and done safely)? We have seen several solutions on Stumble Upon that if combined possibly could work, but all profiles on our site currently have their own physical directories rather than being assembled on the fly by a script.

更新: @乔恩 - 林的报价为<一个解决类似的情况href=\"https://stackoverflow.com/questions/18625414/how-to-access-directorys-index-php-without-a-trailing-slash-and-not-get-301-red\">How进入目录的index.php文件没有一个斜线,并没有得到301重定向 - 但我们没有弄清楚如何将其应用到我们的(如上所述)

Update: @jon-lin offered a solution to a similar situation at How to access directory's index.php without a trailing slash AND not get 301 redirect -- but we didn't figure out how to apply it to ours (described above).

推荐答案

通过在<一个通过添加@乔恩林建议code的一部分href=\"https://stackoverflow.com/questions/18625414/how-to-access-directorys-index-php-without-a-trailing-slash-and-not-get-301-red\">How进入目录的index.php文件没有尾随斜线,并没有得到301重定向(内部改写了结尾的斜线回),我们实际上做这项工作:

By adding part of the code suggested by @jon-lin at How to access directory's index.php without a trailing slash AND not get 301 redirect (internally rewriting the trailing slash back in), we actually made this work:

# Vanity URLs

DirectorySlash Off

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /profiles/$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ /$1/

有关古驰对时尚NET配置文件(位于 /型材/古奇/ )现在可以在的 https://www.fashion.net/gucci - 没有尾随斜线!谢谢@乔恩林!!!!

The profile for Gucci on FASHION NET (located at /profiles/gucci/) can now be accessed at https://www.fashion.net/gucci -- with no trailing slash! Thank you, @jon-lin!!!!

这篇关于虚荣的网址没有在Apache尾随斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆