我想创建一个 .htaccess 文件并向其中添加以下重写规则:
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
我在 xampp 服务器(Apache 版本 2.4.4)中的虚拟主机设置是:
<Directory C:/vhosts>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot C:/vhosts/phpcs5
ServerName phpcs5
</VirtualHost>
谁能建议我如何编写我的 .htaccess 文件?对不起,如果这个问题对你来说太普通了;我是 Apache mod_rewrite 的新手。谢谢你。
当我尝试将这些规则置于以下位置时会出错
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /phpcs5
//rules//
</IfModule>
这是我的 .htaccess 文件,它给出了错误
<IfModule mod_rewrite.c>
# Enable mod_rewrite
RewriteEngine On
CHAPTER 7 ■ SEARCH ENGINE OPTIMIZATION 192
# Specify the folder in which the application resides.
# Use / if the application is in the root.
RewriteBase /tshirtshop
# Rewrite to correct domain to avoid canonicalization problems
# RewriteCond %{HTTP_HOST} !^www\.example\.com
# RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Rewrite URLs ending in /index.php or /index.html to /
RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
# Rewrite category pages
RewriteRule ^.*-d([0-9]+)/.*-c([0-9]+)/page-([0-9]+)/?$ index.php?Depart
mentId=$1&CategoryId=$2&Page=$3 [L]
RewriteRule ^.*-d([0-9]+)/.*-c([0-9]+)/?$ index.php?DepartmentId=$1&Cate
goryId=$2 [L]
# Rewrite department pages
RewriteRule ^.*-d([0-9]+)/page-([0-9]+)/?$ index.php?DepartmentId=$1&Pag
e=$2 [L]
RewriteRule ^.*-d([0-9]+)/?$ index.php?DepartmentId=$1 [L]
# Rewrite subpages of the home page
RewriteRule ^page-([0-9]+)/?$ index.php?Page=$1 [L]
# Rewrite product details pages
RewriteRule ^.*-p([0-9]+)/?$ index.php?ProductId=$1 [L]
</IfModule>