如何在Localhost中使用htaccess更改单个页面URL?

时间:2015-03-05 05:47:15

标签: php .htaccess

我必须将页面网址更改为其他网址。我在localhost中测试它。

我有一个页面网址http://localhost/casanainternational.com/trunk/php/test.php。我想在我输入http://localhost/casanainternational.com/trunk/php/payment-failure时访问test.php页面。

这是我的htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)_(.*)_(.*)_(.*)_(.*).html$ index.php?module=$1&page=$2&action=$3&id=$4&status=$5 [L]
RewriteRule ^(.*)_(.*)_(.*)_(.*).html$ index.php?module=$1&page=$2&action=$3&id=$4 [L]
RewriteRule ^(.*)_(.*)_(.*).html$ index.php?module=$1&page=$2&action=$3 [L]

3 个答案:

答案 0 :(得分:0)

以下代码将解决您的问题

RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost/casanainternational.com/trunk/php/test.php $ [OR]
RewriteRule (.*)$ http://localhost/casanainternational.com/trunk/php/payment-failure.$1 [R=301,L]

答案 1 :(得分:0)

您可以遵守以下规则:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC]
RewriteRule ^payment-failure/?$ test.php [L,NC]

RewriteRule ^(.*)_(.*)_(.*)_(.*)_(.*)\.html$ index.php?module=$1&page=$2&action=$3&id=$4&status=$5 [L,QSA]
RewriteRule ^(.*)_(.*)_(.*)_(.*)\.html$ index.php?module=$1&page=$2&action=$3&id=$4 [L,QSA]
RewriteRule ^(.*)_(.*)_(.*)\.html$ index.php?module=$1&page=$2&action=$3 [L,QSA]

答案 2 :(得分:0)

我已经写了一篇关于此的文章,请访问:如何创建干净的SEO友好URL

http://askguyson.com/how-to-create-clean-seo-friendly-url/