首页 > 解决方案 > URL 重写内部服务器错误

问题描述

我正在尝试在我的类别页面上重写一个 url。

https://www.samedicalspecialists.co.za/category?category=breast-surgeon

我想做:

https://www.samedicalspecialists.co.za/category/breast-surgeon

我的 htaccess 文件中有这个

RewriteEngine On

RewriteRule ^category/([^/]*)$ /category?category=$1 [L]

当我单击类别时出现内部服务器错误,请帮助

更新完整的 htaccess 文件

RewriteEngine On
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# if a file without .php extension is requested, rewrite it to .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.*)$ $1.php [L]
# rewrite everything else (except /listing) to /listing?url=
RewriteCond %{REQUEST_FILENAME} !listing
RewriteRule ^([^.]+)$ /listing?url=$1 [L]

#categories
Options -MultiViews
RewriteRule ^category/([^/]*)$ /category?category=$1 [L]

其他规则仅适用于类别

标签: php.htaccess

解决方案


更改顺序:

RewriteEngine On
RewriteCond %{HTTPS} off 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#categories
RewriteRule ^category/([^/]*)$ /category?category=$1 [NC,L]

# if a file without .php extension is requested, rewrite it to .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.*)$ $1.php [L]

# rewrite everything else (except /listing) to /listing?url=
RewriteCond %{REQUEST_FILENAME} !listing
RewriteRule ^([^.]+)$ /listing?url=$1 [L]

推荐阅读