繁体   English   中英

用.htaccess重写URL

[英]Rewriting an URL with .htaccess

在面对htaccess重写规则的许多问题后,目前我决定将其更改为更基本的内容,但是我无法获取最终页来获取ID。

我的.htaccess是:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /article\.php\?issue=(.*)&edition=(.*)&id=(.*)&title=(.*)\ HTTP
RewriteRule ^ /article/%2/%3/%4/%5\? [R=302,L]
RewriteRule ^article/(.*)/(.*)/(.*)/(.*)$ /article.php?issue=$1&edition=$2&id=$3&title=$4 [L]

如何获取文章页面以获取ID号?

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)\.html$ /article.php?      issue=$1&edition=$2&id=$3&title=$4 [L]

你可以使用这个网站

http://www.generateit.net/mod-rewrite/index.php

以下应该工作:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /article\.php\?issue=(.*)&edition=(.*)&id=(.*)&title=(.*)\ HTTP
RewriteRule ^ /article/%2/%3/%4/%5\? [R=302,L]

RewriteRule ^article/(.*)/(.*)/(.*)/(.*)$ /article.php?issue=$1&edition=$2&id=$3&title=$4 [L]

应该改变
http://website.local.co.uk/article.php?issue=1&edition=leeds&id=1392214680-926677045&title=dearly-noted-presents---lace-and-leather

http://website.local.co.uk/article/1/leeds/1392214680-926677045/dearly-noted-presents---lace-and-leather

编辑:

<?php 
    echo $_GET["issue"];
    echo $_GET["edition"];
    echo $_GET["id"];
    echo $_GET["title"];
?>

当您确定重定向正常运行时,可以将R=302更改为R=301

您可以使用以下代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{THE_REQUEST} \s/article\.php\?issue=([^&]*)&edition=([^&]*)&id=([^&]*)&title=([^&\s]*)
RewriteRule ^ /article/%1/%2/%3/%4? [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /article.php?issue=$1&edition=$2&id=$3&title=$4 [L,QSA,NC]

在这里使用-MultiViews非常重要。 Option的MultiViewsApache's content negotiation module ,该Apache's content negotiation modulemod_rewrite之前运行,并使Apache服务器匹配文件扩展名。 因此/file可以位于URL中,但它将提供/file.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM