使用 htaccess 重写创建我自己的tinyurl

发布于 2024-09-16 10:11:32 字数 188 浏览 3 评论 0原文

我想在我的 htaccess 文件中创建一个 mod 重写,可以将

mydomain.com/abCdE

更改为: mydomain.com/controller/view/parameter/abCdE

提前致谢!

PS我正在使用 Zend Framework

Stefano

I would like to create a mod rewrite in my htaccess file that will can change this:

mydomain.com/abCdE

to this:
mydomain.com/controller/view/parameter/abCdE

Thanks in advance!

P.S. I'm using Zend Framework

Stefano

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御弟哥哥 2024-09-23 10:11:32

我过去创造过这种东西。这就是您想要的:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) /parser.php?q=$1 [L,QSA]

这样您网站上的每个现有文件和目录仍然可以工作,并且其他所有内容(*包括任何额外的 _GET 参数!)也将被传递。

如果您将其放入 .htaccess 文件中,请将 RewriteRule 更改为

    RewriteRule (.*) parser.php?q=$1 [L,QSA]

This 应该可以彻底回答您的问题。

I've created this sort of thing in the past. This is what you want:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) /parser.php?q=$1 [L,QSA]

That way every single existing file and directory on your website will still work, and every thing else (*including any extra _GET parameters!) will be passed too.

If you're putting this inside an .htaccess file, change the RewriteRule to

    RewriteRule (.*) parser.php?q=$1 [L,QSA]

This should thoroughly answer your question.

黄昏下泛黄的笔记 2024-09-23 10:11:32

您可以使用 mod_rewrite 将所有(或几乎所有)请求重定向到一个 PHP 文件,并使其完成这项工作:

RewriteEngine on  
RewriteRule (.*) /parser.php?q=$1

如果您想保留某些页面,您可以设置条件:

RewriteEngine on

# Makes root of your site not to redirect to parser:
RewriteCond %{REQUEST_URI} !^/$            

# Same for mypage.php
RewriteCond %{REQUEST_URI} !^/mypage.php$

# testdir and all files in it are not redirected to parser
RewriteCond %{REQUEST_URI} !^/testdir/

RewriteRule (.*) /controller/view/parameter$1

You can use mod_rewrite to redirect ALL (or almost all) requests to one PHP file, and make it do the job:

RewriteEngine on  
RewriteRule (.*) /parser.php?q=$1

If you want to leave some pages, you may put conditions:

RewriteEngine on

# Makes root of your site not to redirect to parser:
RewriteCond %{REQUEST_URI} !^/$            

# Same for mypage.php
RewriteCond %{REQUEST_URI} !^/mypage.php$

# testdir and all files in it are not redirected to parser
RewriteCond %{REQUEST_URI} !^/testdir/

RewriteRule (.*) /controller/view/parameter$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文