如何使用htaccess的偶然的网址...?如何使用、网址、htaccess

2023-09-02 01:10:47 作者:言辞

我一派,看着stackover流,但我没能真正理解的答案

I googled and looked on stackover flow but i failed to really understand the answers

我,M不是要重定向,但改变URL格式

I;m not trying to REDIRECT but CHANGE the WAY the URLS LOOK

我想改变这些到新网址

www.site.com/abc.php到www.site.com/~~V (我的索引页目前有我的登录页面,所以我不能使用的index.php)

www.site.com/abc.php to www.site.com/ (my index page currently has my login page so I can't use the index.php)

www.site.com/abc.php#123.php到www.site.com/123.php~~V

www.site.com/abc.php#123.php to www.site.com/123.php

更新:

好了,我该怎么做,那么

Ok, how can I do this then

www.site.com/abc.php到www.site.com/abc /

www.site.com/abc.php to www.site.com/abc/

,这样,当一个散列链路present它看起来像

so that when a hash link is present it looks like

www.site.com/abc/#123.pho

www.site.com/abc/#123.pho

,或者如果可能的

www.site.com/abc/#123 /

www.site.com/abc/#123/

推荐答案

除了在重定向对方的回答,如果你想要更高级的转发,你可以使用Apache RewriteEngine叙述模块。 然后,您可以使用正则表达式,其中可能包括的子模式。

In addition to the other answer on redirects, if you want more advanced forwarding you can use the Apache RewriteEngine module. You can then use regexps, which may include subpatterns.

从我的网站为例,我创建了模式我已经导入了从博客到字preSS后。每当有人访问的URL如 http://www.twistedmind.nu/2006_03_01_archive.html 他 ð被重定向到 http://twistedmind.nu/2006/03

Example from my site, I created the patterns after I've imported everything from blogger to wordpress. Whenever someone visits an URL like http://www.twistedmind.nu/2006_03_01_archive.html he'd be redirected to http://twistedmind.nu/2006/03

RewriteEngine叙述上 RedirectMatch 301(([0-9] *)_([0-9] *)_([0-9]的)(。的)(HTML))$的 http://twistedmind.nu/ $ 2 / $ 3 / RedirectMatch 301(([0-9]的)(的)(HTML)。)$ 的http:// twistedmind.nu/~~V $ 1

RewriteEngine on RedirectMatch 301 (([0-9]*)_([0-9]*)_([0-9])(.)(.html))$ http://twistedmind.nu/$2/$3/ RedirectMatch 301 (([0-9])(.)(.html))$ http://twistedmind.nu/$1

根据对方的回答,你不能对一切的经过哈希标签#虽然相匹配。

Based on the other answer, you can't match on everything that's after the hash tag # though.

其他的例子(评论后加入):

Other example (added after comment):

RedirectMatch 301(*)。PHP $ http://www.mysite.com/ $ 1

RedirectMatch 301 (.*).php$ http://www.mysite.com/$1

这应该剥去PHP扩展的所有链接,新链接(withouth的.PHP)应该存在。

This should strip the .php extension from all links, the new link (withouth .php) should exist.

您可以使用mod_rewrite,如果你想创造一个虚拟的URL重定向类似MYSAMPLE到mysample.php。请参见 http://httpd.apache.org/docs/1.3/mod/mod_rewrite。 HTML 一个解释。

You can use mod_rewrite if you want to create 'virtual' urls that redirect something like mysample to mysample.php. See http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html for an explanation.