带有特定参数的htaccess的漂亮URL

时间:2019-02-06 00:18:49

标签: php apache .htaccess mod-rewrite

我想使用以下形式的URL:https://domain(:port)/lang/x/y/z/other

使用此htaccess文件,我无法完全实现所需的功能。

如果输入URL https://localhost:port/lang/,则会丢失端口。 如果输入URL https://localhost:port/lang,我得到URL https://localhost:port/langx/y/z

请帮助我!

Options +FollowSymLinks
RewriteEngine On

#LIVE
RewriteBase /

#--------------------------------------
#-- 404 & 500 Redirects
#--------------------------------------
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

#--------------------------------------
#-- Force HTTPS
#--------------------------------------
RewriteCond %{HTTP_HOST} !=localhost$ [NC]
RewriteCond %{SERVER_PORT} !=8088
RewriteCond %{SERVER_PORT} !=8080
RewriteCond %{HTTPS} !=on
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


RewriteRule ^(actions)($|/) - [L]

#--------------------------------------
#-- Add trailing PHP and Params
#--------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.php?param1=$2&param2=$3&param3=$4&param4=$5 [B,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ $1.php?param1=$2&param2=$3&param3=$4 [B,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)$ $1.php?param1=$2&param2=$3 [B,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#check for the existance of a PHP file first or else the 404 won't work
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^/]+)$ $1.php?param1=$2 [B,QSA,L]

RewriteRule ^(.*)/$ $1 [R=301,L]

0 个答案:

没有答案