删除扩展后重写url

时间:2014-01-13 17:36:13

标签: php apache .htaccess mod-rewrite

我需要你的帮助。

我在删除扩展程序后重写动态网址时遇到问题,我已重写此网址但不起作用:

.htaccess像这样:

<IfModule mod_rewrite.c>
Options -Multiviews
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

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

#remove .php extension  2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$  /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

# Removes index.php from ExpressionEngine URLs  3
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/$1 [L]

#rewrite url 4
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /article\.php\?id_ article =([^&\ ]+)([^\ ]*)
RewriteRule ^/article/%1?%2 [L,R=301] 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/     
RewriteRule ^(([^/]+/)*[^.]+)\.php $1 [R=301,L]
</IfModule> 

结果: 1 + 2 + 3工作正常,但4工作不正常

提前致谢

2 个答案:

答案 0 :(得分:0)

尝试重新排序规则并在内部重写之前保留301规则:

Options -Multiviews
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

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

#rewrite url 4
RewriteCond %{THE_REQUEST} /article\.php\?id_article=([^&\ ]+)([^\ ]*)
RewriteRule ^ /article/%1?%2 [L,R=301] 

RewriteRule ^article/([^/]+)/?$ /article.php?id_article=$1 [L,QSA] 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/     
RewriteRule ^(([^/]+/)*[^.]+)\.php $1 [R=301,L]

#remove .php extension  2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$  /$1 [R=301,L]

# Removes index.php from ExpressionEngine URLs  3
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

# Directs all EE web requests through the site index file 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/$1 [L]

答案 1 :(得分:0)

这是我最后一次.htaccess代码:
选项-Multiviews

选项+ FollowSymLinks

RewriteEngine On

RewriteBase /

添加www

RewriteCond%{HTTP_HOST}!^ www.mondomain.fr $ [NC]

RewriteRule ^(。*)$ http://www.mondomaine.fr/ $ 1 [R = 301,L]

重写动态网址

RewriteCond%{THE_REQUEST} /article.php\?id_article =([^&amp; \] +)([^ \] *)

RewriteRule ^ / article /%1?%2 [L,R = 301]

RewriteRule ^ article /([^ /] +)/?$ /article.php?id_article=$1 [L,QSA]

RewriteCond%{THE_REQUEST} ^ [AZ] + \ /([^ /] + /) [^。#?\] + .php([#?] [^ \] ) ?\ HTTP /

RewriteRule ^(([^ /] + /)* [^。] +)。php $ 1 [R = 301,L]

删除.php扩展名

RewriteCond%{REQUEST_FILENAME}!-d

RewriteRule ^(。*)/ $ / $ 1 [R = 301,L]

从ExpressionEngine URL

中删除index.php

RewriteCond%{THE_REQUEST} ^ GET。* index.php [NC]

RewriteCond%{REQUEST_URI}!/ system /.* [NC]

RewriteRule(。?)index.php / (。*)/ $ 1 $ 2 [R = 301,NE,L]

RewriteCond%{REQUEST_FILENAME}!-d

RewriteCond%{REQUEST_FILENAME} .php -f

RewriteRule ^(。*)$ $ 1.php [L]

通过站点索引文件

指示所有EE Web请求

RewriteCond%{REQUEST_FILENAME}!-f

RewriteCond%{REQUEST_FILENAME}!-d

RewriteCond%{REQUEST_FILENAME}!-l

RewriteRule ^(。*)$ /index.php/$1 [L]