如何使用 htaccess 来获取 URL...?
我用谷歌搜索并查看了 stackover flow,但我未能真正理解答案
;我不是试图重定向,而是更改 URL 的外观方式
我想将这些更改为新的 url
www.site.com/abc.php 到 www .site.com/ (我的索引页面当前有我的登录页面,所以我无法使用index.php)
www.site.com/abc.php#123.php 到 www.site.com/123.php
更新:
好的,我该怎么办执行此操作,然后从
www.site.com/abc.php 到 www.site.com/abc/,
这样当存在哈希链接时,它看起来像
www.site.com/abc/#123.pho
或如果可能的话
www.site .com/abc/#123/
I googled and looked on stackover flow but i failed to really understand the answers
I;m not trying to REDIRECT but CHANGE the WAY the URLS LOOK
I want to change a these into the new urls
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 to www.site.com/123.php
UPDATE:
Ok, how can I do this then
www.site.com/abc.php to www.site.com/abc/
so that when a hash link is present it looks like
www.site.com/abc/#123.pho
or if possible
www.site.com/abc/#123/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了有关重定向的其他答案之外,如果您想要更高级的转发,您可以使用 Apache RewriteEngine 模块。
然后您可以使用正则表达式,其中可能包含子模式。
以我的网站为例,我在将所有内容从 blogger 导入到 wordpress 后创建了这些模式。每当有人访问像 http://www.twistedmind.nu/2006_03_01_archive.html 这样的 URL 时,他就会d 被重定向到 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/$1
根据其他答案,您无法匹配井号标签 # 之后的所有内容。
其他示例(在评论后添加):
RedirectMatch 301 (.*).php$ http://www.mysite.com/< /a>$1
这应该从所有链接中删除 .php 扩展名,新链接(没有 .php)应该存在。
如果您想创建将 mysample 之类的内容重定向到 mysample.php 的“虚拟”url,则可以使用 mod_rewrite。请参阅http://httpd.apache.org/docs/1.3/mod/mod_rewrite。 html 进行解释。
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.
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 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
This should strip the .php extension from all links, the new link (withouth .php) should exist.
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.
您只能对第一个网址使用 .htaccess。
第二个 url 无法使用 .htaccess 进行重定向。
您可以使用 javascript 来实现:
You can use an .htaccess only for the first url.
The second url cannot be redirected with the .htaccess.
You can use javascript for that: