php - How do I redirect all requests to a subpath to another URL?
问题描述
I have a folder in which I store user profile pages. For example, the profile page for the user "JohnDoe" is:
mywebsite.com/user/JohnDoe/index.php
I want to redirect all requests to mywebsite.com/user/*/index.php
to mywebsite.com/user/index.php
.
I read this post and tried redirecting to google.com as a test:
Redirect 301 /user google.com
but this redirects to mywebsite.com/google.com/JohnDoe/index.php
.
I then cleared my browser's cache and tried:
Redirect 301 /user https://www.google.com
Simply put, I am looking for something like:
Redirect 301 /user/*/index.php /user/index.php
but I am not getting redirected. Unfortunately I couldn't find this in the forums. How do I accomplish this, without the existence of the user profile page?
解决方案
希望对你有帮助
将此代码放入 .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^OLDDOMAIN\.com$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]
来自http://www.webconfs.com/154/301-redirects-how-to-redirect-your-website/
推荐阅读
- r - 如何在R中创建具有可变数量列表的列表
- sql - SQL中数组和单列的区别
- laravel - Laravel - 如何为注册用户创建设置页面
- python - 如何使用 pymongo 获取基于 from 和 to date 的文档?
- kubernetes - k8s集群中如何控制每台机器上使用的每个GPU的使用率
- linux - 使用 LD_PRELOAD 加载的库是否会在最后被卸载
- django - /doctor-add-notes NOT NULL 约束处的 Django IntegrityError 失败:
- javascript - 反应 | 无法发布 | mongodb
- bluetooth - 我需要写入哪个 BluetoothLE 句柄才能启用通知?
- javascript - javascript:基于数组替换字符串中的值,高效的解决方案