Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make mod_rewrite suppress processing more rules?

Given my current .htaccess file, how would I modify it to check for an additional URL path like '/src/pub/' and rewrite it to '/' without affecting the current rewrite?

Here's the original .htaccess file:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

and here's my recent attempt (which doesn't work):

RewriteEngine on

RewriteRule ^/src/pub/(.*)$ /$1 [R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

Edit: Here are some examples of what I want to accomplish:

New Additional Rule:

From:  http://www.mysite.com/src/pub/validfile.php
To:    http://www.mysite.com/validfile.php

From:  http://www.mysite.com/src/pub/user/detail/testuser
To:    http://www.mysite.com/user/detail/testuser

Existing Rule (already working):

From:  http://www.mysite.com/user/detail/testuser
To:    http://www.mysite.com/index.php?route=user/detail/testuser
like image 294
Wilco Avatar asked Mar 01 '23 04:03

Wilco


1 Answers

I'm guessing that the problem is that the URL is being rewritten by the first rule, and then rewritten again by the second.

The solution to that is to add the "last" flag to the first rule, like this:

RewriteRule ^/src/pub/(.*)$ /$1 [R,L]
like image 65
TimB Avatar answered Mar 05 '23 16:03

TimB