使用htaccess更改显示的URL

时间:2015-06-04 17:43:38

标签: .htaccess

如何使用HTACCESS重写我的URL?

当访问者访问index.php时,我希望将URL重写为其他内容,尽管访问者将保留在index.php页面上。

这是我尝试过的(我在问之前对此进行了研究,但我自己无法解决):

RewriteEngine on
RewriteRule ^index.php$ testingit.php

基本上,我只是想将index.php改为' testingit.php',只是为了看看它是否有效。

2 个答案:

答案 0 :(得分:1)

所以在这里你是如何做到的:

redirect *** /index.php http://www.yoursite.com/testingit.php

您需要使用以下某项替换***:

  • 301-永久重定向意味着浏览器更新书签等。
  • 302 - 用于临时重定向
  • 这是我找到的指南的链接:

    https://www.branded3.com/blog/htaccess-mod_rewrite-ultimate-guide/

    希望这会有所帮助:)

    制作漂亮的网址:

    RewriteEngine On    # Turn on the rewriting engine
    RewriteRule    ^home/?$    index.php    [NC,L]    
    

    答案 1 :(得分:0)

    您可以在RewriteEngine On RewriteBase /testwebsite/ # external redirect from actual URL to pretty one RewriteCond %{THE_REQUEST} /index\.php[?\s] [NC] RewriteRule ^ home [R=302,L,NE] # internal forward from pretty URL to actual one RewriteRule ^home/?$ index.php [L,NC] 文件中使用此代码:

    {{1}}