博客文章的漂亮网址

时间:2015-08-11 11:22:38

标签: php yii2

我在解决这个问题上遇到了困难。

我希望我的博文显示为 http://www.domain.com/post-title-here/ 现在它是http://www.domain.com/site/blog-post?post_name=post-title-here

有什么方法可以改变这个吗? 另外,我使用的是Yii2 Framework。

在我的UrlManager中有以下规则:

'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '' => 'site/index',
            '<alias:mail-senden|kundennutzen|berater|garantie|leistungen|impressum|referenzen|blog|kontakt>' => 'site/<alias>',
            'category/<category:.*?>' => 'site/blog-category',
            'admin' => 'admin/index',
            '<alias:update-general-info|get-all-posts|add-post|insert-post|delete-post|edit-info|edit-post|register|login|process-login|logout|forgot-password|process-forgot-password|reset-password|update-password|update-info|update-post>' => 'admin/<alias>',
            /*'<post_name:.*?>' => 'site/blog-post',*/
        ]
    ],

我的.htaccess文件看起来像这样:

# Rewrite urls - Turn on
RewriteEngine on
RewriteBase /yii2-projects/kundennutzenberater.de/
RewriteRule /(.*)/$ /site/blog-post?post_name=$1 [NC,P]


# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward it to index.php
RewriteRule . /index.php

# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

0 个答案:

没有答案