简体   繁体   中英

How to modify this URL in .htaccess?

I want to modify URL with a check.

  1. If there exists experiment as second folder, then do this

    {site}.com/dashboard/experiment/closed/.../

    to

    {site}.com/experiment/closed/.../

  2. If no experiment found in path, then don't do anything. For eg

    {site}.com/dashboard/ex-view/closed/.../

How do I achive this using htaccess. I'm using Laravel 5.1.

This is what I tried but it doesn't meet the second condition.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^experiment/(.*)$ /$1 [L,NC,R]

You can try this rule in the .htaccess in the root. The should only affect URL with experiment as the second folder.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^.+/experiment/(.*)$ /experiment/$1 [L,NC,R]

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