简体   繁体   English

htaccess尾随斜线问题

[英]htaccess trailing slash issue

I am getting some problem for without trailing slash url. 我在没有尾随斜杠的网址时遇到了一些问题。 I searched in Google, but not able to get the exact result. 我在谷歌搜索过,但无法得到确切的结果。

  From Url : local.xxxx.com/stories

When I am trying with the above Url, It redirects to 当我尝试使用上面的Url时,它会重定向到

  To Url : local.xxxx.com/sapp/View//stories/

Htaccess: .htaccess中:

DirectorySlash Off
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule ^ /app/View/%{REQUEST_URI} [L]

Now I am getting 403 Forbidden error. 现在我收到403 Forbidden错误。 You don't have permission to access /app/View//storieson this server. 您无权在此服务器上访问/ app / View // stories。

If I will add trailing slash, then its working perfectly. 如果我将添加尾部斜杠,那么它的工作完美。 If there is no slash, we can add slash at the end of the url if there are no params. 如果没有斜杠,如果没有参数,我们可以在url的末尾添加斜杠。

Can any body suggest how can I achieve this. 任何人都可以建议我如何实现这一目标。

It is most likely due to the fact that /app/View/stories/ is a real directory and Apache's mod_dir is adding a trailing slash. 这很可能是因为/app/View/stories/是一个真实的目录而Apache的mod_dir正在添加一个尾部斜杠。

You can fix using this code: 您可以使用此代码进行修复:

DirectorySlash Off
RewriteEngine On

# internally add a trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule [^/]$ /app/View/%{REQUEST_URI}/ [L] 

RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule ^ /app/View/%{REQUEST_URI} [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM