htaccess检查查询字符串是否存在,否则使用先前的规则

时间:2016-06-24 10:17:47

标签: apache .htaccess mod-rewrite

我正在尝试转换此网址

http://127.0.0.1/kurumsal/index.php?sayfa=referans&page=2

到这个

http://127.0.0.1/kurumsal/index/sayfa/referans/page/2/

但并非每个页面都具有引用page = 2查询字符串的分页。如果'page'查询字符串不存在,我想只使用查询字符串的第一部分。

所以没有分页查询字符串就是http://127.0.0.1/kurumsal/index/sayfa/referans/

遵循一些教程,但没有运气,这是我的htaccess

RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)page=($|&)
RewriteRule ^sayfa/([^/]*)/([^/]*)/$ /kurumsal/index.php?sayfa=$1&page=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sayfa/([^/]*)/$ /kurumsal/index.php?sayfa=$1 [L]

3 个答案:

答案 0 :(得分:1)

尝试使用此规则:

RewriteEngine On
RewriteRule ^kurumsal/index/sayfa/([^/]*)/page/([^/]*)$ /kurumsal/index.php?sayfa=$1&page=$2 [L]

答案 1 :(得分:1)

您可以在root/.htaccess

中使用此规则
RewriteEngine on

RewriteCond %{THE_REQUEST} /kurumsal/index\.php\?sayfa=([^\&]+)(?:&page=)?(.*?)\sHTTP [NC]
RewriteRule ^ /kurumsal/index/sayfa/%1/%2? [L,R]
RewriteRule ^(?:kurumsal/)?index/sayfa/([^/]+)/?(.*?)/?$ /kurumsal/index.php?sayfa=$1&page=$2 [L]

答案 2 :(得分:1)

试试这个

{{1}}