0

大家好,我有一个 htaccess 的问题。

我想要这个 URL domain.com/index?article=28&title=velky-biel-karlova-ves (它没有 index.php,因为我用 htaccess 隐藏了 .php 扩展名。

我想要这个网址domain.com/clanok/28/velky-biel-karlova-ves

我用了这段代码

我的 htaccess 文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^clanok/([\d]+)/([\w-]+)/?$ index.php?article=$1&title=$2 [NC,L]

RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

我的 index.php 文件:

<a href="index.php?article=<?php echo urlencode($row['id']); ?>&title=<?php     echo createSlug($row['title']); ?>" title="">

它不起作用。

谢谢帮助。

4

1 回答 1

1

像这样尝试你仍然必须提到 index.php 你的 php 隐藏规则与此不同,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^clanok/([\d]+)/([\w-]+)/?$ index.php?article=$1&title=$2 [NC,L]

请确保此规则与您现有的规则不冲突。

于 2017-02-01T11:25:21.253 回答