.htaccess文件和重写规则

时间:2013-11-03 15:38:44

标签: apache .htaccess mod-rewrite url-rewriting

我想创建一个.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> 

0 个答案:

没有答案