简体   繁体   中英

How to remove last part of my URL with .htaccess?

Currently I have an URL that looks like :

www.mywebsite.com/confirm/ZChCQhXNJ5i

The last part of the URL is a random string. I want to remove it from my URL to get something like that

www.mywebsite.com/confirm

I've tried many things such as RewriteRule ^(confirm)/.+$ /$1 [L,NC] but I really don't understand the .htaccess syntax.

Edit 1 - Here is my .htaccess file.

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
  RewriteRule ^(.*) - [E=BASE:%1]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]

  RewriteRule ^(confirm)/.$ /$1 [L,NC]
</IfModule>

Edit 2 - Your answers helped me, here is the solution I found :

RewriteRule ^(confirm)/(.*) /$1 [L,R=301]

Have you tried using this RewriteRule?

RewriteEngine On
RewriteRule ^(.*)/ZChCQhXNJ5i /$1 [L,R=301]

When I test this it works perfectly. See here: http://htaccess.mwl.be?share=33ae279c-7597-5935-8bf0-d389add54d0a

It successfully changes your URL to www.mywebsite.com/confirm using a permanent 301 redirection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM