GVKun编程网logo

htaccess:从URL添加/删除尾部斜杠(删除url指定参数)

16

如果您对htaccess:从URL添加/删除尾部斜杠感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于htaccess:从URL添加/删除尾部斜杠的详细内容,我们还将为您解答删

如果您对htaccess:从URL添加/删除尾部斜杠感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于htaccess:从URL添加/删除尾部斜杠的详细内容,我们还将为您解答删除url指定参数的相关问题,并且为您提供关于.htaccess从url中删除问号、.htaccess删除.php并添加url参数、.htaccess删除URL扩展,添加尾随斜杠、.htaccess:从URL中删除公共的有价值信息。

本文目录一览:

htaccess:从URL添加/删除尾部斜杠(删除url指定参数)

htaccess:从URL添加/删除尾部斜杠(删除url指定参数)

我的网站运行的脚本名为-> WSS壁纸脚本

我的问题 ->我一直在尝试强制删除或在URL末尾添加斜杠,以防止重复的内容并清理URL。

我尝试了各种尝试,尝试了所有可以想到的东西,并尝试从Interweb进行加载,但是还没有运气!这可能是一个快速解决方案,但是我已经看了太多了,因此我可能看不到一些显而易见的东西。

因此,我向您提供所有.htaccess代码:

DirectoryIndex index.phpRewriteEngine onRewriteRule ^download/([0-9]+)?/([0-9]+)x([0-9]+)/([^/\.]+) image.php?id=$1&width=$2&height=$3&cropratio=$4&download=1 [L]RewriteRule ^file/([0-9]+)?/([0-9]+)x([0-9]+)/([^/\.]+) image.php?id=$1&width=$2&height=$3&cropratio=$4 [L]RewriteRule ^preview/([0-9]+)?/([0-9]+)x([0-9]+)/([^/\.]+) wallpaper_preview.php?id=$1&width=$2&height=$3&name=$4 [L]RewriteRule ^thumbnail/([0-9]+)?/([0-9]+)x([0-9]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/]+) image.php?wallpaper_id=$1&width=$2&height=$3&cropratio=$4&align=$5&valign=$6&file=$7 [L]RewriteRule ^cat/([0-9]+)?/([^/\.]+)/p([0-9]+) index.php?task=category&id=$1&name=$2&page=$3 [L]RewriteRule ^cat/([0-9]+)?/([^/\.]+)/([0-9a-zA-Z?-]+)/p([0-9]+) index.php?task=category&id=$1&name=$2&sortby=$3&page=$4 [L]RewriteRule ^cat/([0-9]+)?/([^/\.]+)/([0-9a-zA-Z?-]+)-([0-9]+) index.php?task=category&id=$1&sortby=$3&page=$4 [L]RewriteRule ^cat/([0-9]+)?/([^/\.]+) index.php?task=category&id=$1&name=$2 [L]RewriteRule ^tag/([^/\.]+)/([0-9a-zA-Z?-]+)/([0-9]+) index.php?task=tag&t=$1&sortby=$2&page=$3 [L]RewriteRule ^tag/([^/\.]+) index.php?task=tag&t=$1 [L]RewriteRule ^profile/([0-9]+)?/([^/\.]+) index.php?task=profile&id=$1&name=$2 [L]RewriteRule ^profile/comments/([0-9]+)?/([^/\.]+) index.php?task=users_comments&id=$1&name=$2 [L]RewriteRule ^page/([0-9]+) index.php?task=view_page&id=$1 [L]  RewriteRule ^register index.php?task=register [L] RewriteRule ^lost-password index.php?task=lost_pass [L] RewriteRule ^links index.php?task=links [L]RewriteRule ^news/item/([0-9]+)/([^/\.]+) index.php?task=news&id=$1 [L]RewriteRule ^news/page([0-9]+) index.php?task=news&page=$1 [L]RewriteRule ^members/([^/\.]+)-([^/\.]+)/page([0-9]+)? index.php?task=member_list&sort=$1&order=$2&page=$3 [L]RewriteRule ^members index.php?task=member_list [L]RewriteRule ^messages index.php?task=messages [L]RewriteRule ^submit index.php?task=submit [L]RewriteRule ^search/([^/\.]+) index.php?task=search&q=$1 [L]RewriteRule ^search index.php?task=search [L]RewriteRule ^submit index.php?task=submit [L]RewriteRule ^r-([0-9]+)?-([0-9]+)? go.php?id=$1&ref=$2 [L]RewriteRule ^r-([0-9]+)? go.php?id=$1 [L]RewriteRule ^([^/\.]+)/([0-9]+)/([^/\.]+) index.php?task=view&id=$2&name=$3 [L]RewriteRule ^news/([^/\.]+) index.php?task=news&name=$1 [L]RewriteRule ^profile/([^/\.]+) index.php?task=profile&name=$1 [L]RewriteRule ^news index.php?task=news [L]RewriteRule ^page/([^/\.]+) index.php?task=view_page&name=$1 [L]  RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^/\.]+)/([0-9a-zA-Z''?-]+)/([0-9]+) index.php?task=category&name=$1&sortby=$2&page=$3 [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^/\.]+)/([^/\.]+) index.php?task=view&name=$2 [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^/\.]+) index.php?task=category&name=$1 [L]## www reslove ##RewriteCond %{HTTP_HOST} !^www\.RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]## www reslove #### index reslove ##Options +FollowSymLinksRewriteCond %{THE_REQUEST} ^.*/index\.phpRewriteRule ^(.*)index.php$ http://www.epicwallpaper.net/$1 [R=301,L]## index reslove ##

答案1

小编典典

在该RewriteEngine On行下方,添加:

RewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]

实施不拖尾的斜线政策。

要实施斜杠策略:

RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*[^/])$ /$1/ [L,R] # <- for test, for prod use [L,R=301]

编辑 :评论了这些R=301部分,因为,如评论中所述:

小心点R=301!在那里放置它 会使许多浏览器无限期地缓存.htaccess文件
:如果您不能在所有打开它的机器上清除浏览器缓存,它就会以某种方式不可逆转。测试时,最好选择简单RR=302

完成测试后,您可以使用R=301

.htaccess从url中删除问号

.htaccess从url中删除问号

我有一个网站,我想要重写的URL中有一个查询string。 url是domain.com/profile.PHP?user=sven ,我希望它redirect到domain.com/profile/user/sven 。

我创build了一个具有以下规则的htaccess文件:

RewriteEngine On RewriteRule ^/?user/([^/]+)/?$ profile.PHP?user=$1 [L,QSA] RewriteCond %{QUERY_STRING} ^user=([A-Za-z0-9-_]+)$ RewriteRule ^profile.PHP$ domain.com/user/%1?/ [L,R=301]

这工作,但它redirect到的url是: domain.com/user/sven?/

我的问题是,我可以删除? 在url?

.htaccess 403如果url包含另一个htaccess文件的目录,则禁止

将HTTPredirect到HTTPS和WWW到非WWW URL

在Apache 1.3中使用htaccess作为root用户的子目录

Apache目录closures – 站点中断

CodeIgniter PHP的Apache 500内部服务器错误

如何停止.htaccess循环

RewriteRule htaccess始终删除尾部斜杠甚至目录

.htaccess – 将子域redirect到文件夹

如何通过.htaccess设置PHP包含path?

根据请求使用.htaccess强制video/ webm mimetypesuri

更新你的htaccess以下,

<Ifmodulee mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?profile/(.*?)/?$ /profile.PHP?user=$1 [L] RewriteCond %{THE_REQUEST} ^[AZ]{3,9} /profile.PHP?user=([^]+) RewriteRule ^/?profile.PHP$ /users/%1? [L,R=301] </Ifmodulee>

我希望这有帮助。

Probaly所有的问题在这里:

RewriteRule ^profile.PHP$ domain.com/user/%1<strong>?</strong>/ [L,R=301]

这可能会解决您的问题。

.htaccess删除.php并添加url参数

.htaccess删除.php并添加url参数

除非您有其他要求,否则您无需作为单独的规则“删除” .php。您有/signUp/{somevalue},必须重写为/signUp.php?url={somevalue}

这可以通过以下规则来实现:

Options -MultiViews

RewriteEngine On

RewriteRule ^(signUp)/([^/.])+$ $1.php?url=$2 [L]

只要您将somevalue限制为不包含点或斜杠,就无需检查请求是否未映射到文件。除非/signUp也作为目录存在,否则这不可能映射到目录。

somevalue必须包含1个或多个字符。如果您还有其他限制,则应将其包含在正则表达式中。


更新:

谢谢,但这仅适用于注册,我如何使它适用于所有页面?

假设“所有页面”由文档根中包含4个或更多字符的单个路径段组成,仅包含字符a-zA-Z0-9_ (下划线)和-(连字符),然后按如下所示更改上面的RewriteRule

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([\w-]{4,})/([^/.])+$ $1.php?url=$2 [L]

这确实会在重写请求之前检查相应的.php文件是否存在,尽管如果没有其他指令,这可能不是严格必要的。

.htaccess删除URL扩展,添加尾随斜杠

.htaccess删除URL扩展,添加尾随斜杠

我一直在试图让我的客户端的服务器上工作,我正在开发一个网站,但我根本无法得到它的工作。 基本上我试图删除.html扩展名,并添加一个结尾的斜杠(在URL栏中)。

所以如果有人input:

-example.com/home/ ———–去—– example.com/home/

-example.com/home ————转到—– example.com/home/

.htaccess重写通配符subsubdomain和params

htaccess添加.PHP到没有扩展名的所有东西

使用重写规则从url中删除.PHP后,css和img文件有404

在.htaccess中重写查询string

使用.htaccess禁用所有CGI(PHP,perl,…)目录

-example.com/home.html ——转到—– example.com/home/

-example.com/home.html/ —–前往—– example.com/home/

-example.com/home/.html —–前往—– example.com/home/

-example.com/home/.html/ —-前往—– example.com/home/

这是我的.htaccess到目前为止,这完美的作品,并做我想要的一切,除了在末尾添加尾部的斜线。

这是代码:

#force www RewriteCond %{HTTP_HOST} !^www. RewriteRule ^(.*) http://www.%{HTTP_HOST}/1 [R=301,L] # remove .html ONLY if requested directly RewriteCond %{THE_REQUEST} (.htmlsHTTP/1) RewriteRule ^(.+).html /1 [R=301,L,QSA] # remove trailing slash ONLY if it is not an existing folder RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/ /1 [L,R=301] # rewrite to FILENAME.html if such file does exist and is not a folder RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^(.*) /1.html [L,QSA]

我在服务器上托pipe的所有文件都是FILENAME.html的forms,位于根目录中。

所以,如果有人能帮助我,我会很感激。

允许在Content Security Policy(CSP)中通过$ .getscript()插入file.js

获取价值和redirect与htaccess

mod_rewrite,.htaccess连接到MysqL数据库

.htaccess重写正则expression式:匹配除“索引”

从url中移除app / webroot

修改.htaccess文件并插入以下内容

说明: http : //eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/

例:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^([^/]+)/$ $1.html # Forces a trailing slash to be added RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L]

更新页面上的链接

然后,所有的超链接,CSS链接,图像等将需要更新为具有绝对URL( http://www.site.com/style.css )或相对,并以../开头。 否则,您将遇到诸如未加载的CSS,不工作的链接等问题。

总结

以上是小编为你收集整理的.htaccess删除URL扩展,添加尾随斜杠全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

.htaccess:从URL中删除公共

.htaccess:从URL中删除公共

我如何删除/公开/从我的url?

问题

当我访问/app/about URL更改为/app/public/about和app/user/2更改为/app/user.PHP/?username=2

Htaccess重写URL来哈希锚在主页上

configuration只允许特定的域使用.htaccess访问某些文件夹

无法重写url并在.htaccess中追加参数

.htaccess不工作的Apache-Tomcat

用简单的htaccess规则redirect循环

build立

/ app / .htaccess

公用文件夹外的.htaccess包含:

Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase /app/ # remove /public/ from URL RewriteCond %{REQUEST_URI} !/public [NC] RewriteRule ^(.*)/?$ public/$1

这工作正常。 当我访问localhost:8888/app/它加载公用文件夹内的index.PHP文件。

/ app / public / .htaccess

公用文件夹中的.htaccess包含:

Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f # Add trailing slash RewriteCond %{REQUEST_URI} ^(.+[^/])$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . %1/ [L,R=301] # API Pages # ------------------------------------------------------------ RewriteRule ^user/([a-z0-9]+)/?$ user.PHP?username=$1 [L,NC] # Generic Pages # ------------------------------------------------------------ RewriteRule ^about/?$ about.PHP [L,NC] # Error Pages # ------------------------------------------------------------ ErrorDocument 404 /404.PHP

相关 : 在“公共”文件夹中使用索引进行URL重写

使用mod_rewrite后,我的css imges jspath被改变了

使用查询string将urlredirect到url友好的目录,例如url

ProxyPass和ProxyPassReverse可以在htaccess中工作吗?

htaccess的HTTPSredirect到secure.domain.com,非HTTPS到www.domain.com

.htaccess资源解释为脚本,但是以MIMEtypestext / html传输

您的# Add trailing slash规则似乎是问题。 你可以尝试评论出来进行测试。

/app/.htaccess

Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase /app/ ## Adding a trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{THE_REQUEST} s/+(.+?[^/])[?s] [NC] RewriteRule ^ /%1/ [L,R=301] # remove /public/ from URL RewriteCond %{REQUEST_URI} !/public/ [NC] RewriteRule ^(.*?)/?$ public/$1 [L]

总结

以上是小编为你收集整理的.htaccess:从URL中删除公共全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

今天的关于htaccess:从URL添加/删除尾部斜杠删除url指定参数的分享已经结束,谢谢您的关注,如果想了解更多关于.htaccess从url中删除问号、.htaccess删除.php并添加url参数、.htaccess删除URL扩展,添加尾随斜杠、.htaccess:从URL中删除公共的相关知识,请在本站进行查询。

本文标签: