Apache 使用.htaccess删除url的一部分
有一段时间我的页面结构是这样的:Apache 使用.htaccess删除url的一部分,apache,.htaccess,Apache,.htaccess,有一段时间我的页面结构是这样的: 现在我想将其更改为: 我怎样才能做到最好 这是我已经拥有的: RewriteEngine On # Include "www" and change "http" to "https". RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} off RewriteRule
现在我想将其更改为: 我怎样才能做到最好 这是我已经拥有的:
RewriteEngine On
# Include "www" and change "http" to "https".
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Ignore some stuff.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The page part.
RewriteRule ^([a-zA-Z0-9/_\-]+)$ index.php?mode=page&slug=$1 [NC]
RewriteRule ^([a-zA-Z0-9/_\-]+)/$ index.php?mode=page&slug=$1 [NC,L]
# Redirect /page/SLUG to /SLUG?
大概是这样的:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^page/(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^page/(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} on
RewriteRule ^page/(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
试试下面的条件和规则
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/_\-]+)/?$ index.php?mode=page&slug=$1 [NC,L]
如果请求方案为https,则不会重定向请求。