【问题标题】:Removing trailing slash for sub directory url indexing删除子目录 url 索引的尾部斜杠
【发布时间】:2014-05-26 08:55:50
【问题描述】:
example.com/contact.php  <- I want to like this -> example.com/contact

而这也想要……

example.com/contact/ (havent real directory. want to redirect /contact)
example.com/contact.(any extension redirect to /contact)

我想喜欢这个..请帮我做这个

如果有真正的目录想去那里......

编辑:

example.com/watch.php?id=1995/english-videos 这个链接不起作用.. 我想像这样重定向example.com/contact 不想要斜线。我想使用这个链接example.com/watch.php?id=1995/english-videos

/.htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^col3negmovie.com$
RewriteRule ^(.*)$ "http\:\/\/www\.col3negmovie\.com\/$1" [R=301,L]


Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^col3negmovie\.com$
RewriteRule ^(.*)$ http://www.col3negmovie.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+watchnew1\.php\?id=([^\s&]+) [NC]
RewriteRule ^ watch/%1? [R=301,L]

RewriteRule ^watch/(.+?)/?$ watchnew1.php?id=$1 [L,QSA,NC]

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]

# remove .php extension 
RewriteCond %{THE_REQUEST} \s/+(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# add .php extension internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

example.com/watch.php?id=1995/english-videos 不起作用 :( 我想要这样的其他链接 example.com/contactexample.com/about 但这个链接想要那样

【问题讨论】:

  • 为什么要从真实目录中删除尾部斜杠?如果该目录没有默认的index.php,这是很大的安全风险。
  • 哎呀!为什么?什么问题?你能描述一下我吗
  • 我已经写了为什么是风险的原因。
  • 哦,好的,谢谢...朋友:)
  • 一般来说避免DirectorySlash Off在你的路径中的任何地方。

标签: apache .htaccess slash


【解决方案1】:

你的完整 .htaccess 可以是这样的:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^col3negmovie\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{THE_REQUEST} \s/+watchnew1\.php\?id=([^\s&]+) [NC]
RewriteRule ^ watch/%1? [R=301,L]

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ $1 [R=301,L]

# remove .php extension 
RewriteCond %{THE_REQUEST} \s/+(.*?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]

RewriteRule ^watch/(.+?)/?$ watchnew1.php?id=$1 [L,QSA,NC]

# add .php extension internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

【讨论】:

  • 最后一个是什么意思#在内部添加.php扩展名
  • 工作,但它重定向到喜欢这个 /contact/ 但我想 /contact 这样
  • 有一些问题.. 像这样的链接不起作用:( example.com/watch.php?id=1995/english-videos
  • 你能发布你最新的有问题的.htaccess吗?
  • 嗯,我在您的问题中没有看到 .htaccess。我需要去工作,稍后我会回来检查。
猜你喜欢
  • 1970-01-01
  • 2017-05-03
  • 1970-01-01
  • 1970-01-01
  • 2018-10-19
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 2019-05-07
相关资源
最近更新 更多