【问题标题】:add trailing slash and remove .htaccess添加尾部斜杠并删除 .htaccess
【发布时间】:2013-04-01 12:31:10
【问题描述】:

我该如何做这样的事情: website.com/store/ 重定向到 website.com/store website.com/outbound/store/5 重定向到 website.com/outbound/store/5/

我想要的是没有前缀的 url 可以删除斜杠,而有前缀的 url 可以添加斜杠

我的 .htaccess:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^pa/?$ /admin/index.php [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ stores.php?store=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^outbound/([^/]*)/([^/]*)$ /outbound.php?type=$1&id=$2 [L]

【问题讨论】:

  • 前缀是什么意思?
  • 前缀是指一些常量,比如最后一行“出站”

标签: apache .htaccess mod-rewrite trailing-slash


【解决方案1】:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# force tailing slash for all urls starting with /outbound/
RewriteRule ^outbound/.*[^/]$ /$0/ [R=301,L]

#remove tailing slash for all except urls starting with /outbound/
RewriteCond $1 !^outbound/
RewriteRule ^(.+)/$ /$1 [R=301,L]

RewriteRule ^pa/?$ /admin/index.php [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^outbound/([^/]*)/([^/]*)/$ /outbound.php?type=$1&id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ stores.php?store=$1 [L]

我也清理了一下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-14
    • 2015-01-15
    • 2012-08-03
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    相关资源
    最近更新 更多