没有尾随斜线虚荣网址 [英] Vanity URLs without trailing slashes

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

问题描述

在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/

该配置文件的Gucci时尚网(位于 /型材/古奇/ )现在可以在的 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!!!!

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

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