如何正确使用htaccess删除扩展和追加变量

时间:2017-11-11 06:26:34

标签: .htaccess

我有一个问题让我的htaccess工作。到目前为止,当使用没有扩展名的URL时,它将成功加载我的php文件。

http://www.example.com/press-release加载/press-release.php

然而,当试图将一个slug传递给press-release.php时,我得到一个500内部服务器错误

http://www.example.com/press-release/page-to-be-loaded-from-db

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /


# Force WWW
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Load post if page or directory isnt found
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_\-\s|%20]*)$ press-release.php?post=$1 [L,QSA]

# Remove extentions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

# Error handeling
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
ErrorDocument 500 /500.html
</IfModule>

0 个答案:

没有答案