首页 > 解决方案 > 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?

标签: php.htaccessredirect

解决方案


希望对你有帮助

将此代码放入 .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/


推荐阅读