【发布时间】:2018-01-06 07:47:50
【问题描述】:
我有这样的链接
http://www.piratefiles.org/dorama/201214213/chase
我想当有人更改原始网址时,例如这样
http://www.piratefiles.org/dorama/201214213/chasegasdfghasfdhga
然后会重定向到 404 not found
你可以试试。那是我的网络。
我的完整 .htaccess 代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^([A-Za-z]+)/([0-9]+)/([\w-]+)/?$ view.php?cat=$1&idp=$2&post=$3&%{QUERY_STRING} [NC,L]
RewriteRule ^category/([\w-]+)/?$ category.php?cat=$1&%{QUERY_STRING} [NC,L]
# To externally redirect /dir/abc.php to /dir/abc
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [QSA,NC,L]
</IfModule>
ErrorDocument 404 http://www.piratefiles.org/404.php
【问题讨论】:
-
您可以在您的 php 代码中执行此操作。如果您使用 MVC 结构,您可以检查是否定义了操作。
标签: php apache .htaccess redirect mod-rewrite