Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Having trouble combining two Rules in htaccess file

Featured Replies

I created a Rule in my HTACCESS file, to hide a sub-folder.

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC]
RewriteRule ^ /%1/%3 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php [NC,L]

The first rule removes all file-extensions : php

The second rule will hide the folder "Project" from the URL

Both these rules are working perfectly.

However, when I tried to add a third rule, to hide another folder, it failed.

This second folder (Rolan) is in the same location as the "Project" folder, so I assumed that it should work simply by copy-pasting the second rule, and then adding a PREFIX to the beginning of the third rule :

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC]
RewriteRule ^ /%1/%3 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/Rolan/$2.php [NC,L]

I added the prefix "gagoo" to the third rule.

 

Also, I removed the [NC,L] from the end of the second rule, and placed it at the end of the third rule.

 

Then, in my PHP code, I wrote the URL as follows : www.example.com/gagoo/Rolan/file_name

 

 

Both the first and second rules are still working. But, for the third rule, I am getting a "FILE NOT FOUND : 404" error

The thing is : I wrote a JavaScript code, which opens "file_name" in a "New Window". (Still, I doubt that this could be the reason for the problem)

  • Author

 

Try this:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC]
RewriteRule ^ /%1/%3 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php
RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/Rolan/$2.php [NC,L]

 

Thanks, Nock.

 

But, I'm still getting the error "404 : File not found"

 

Am I using the correct URL in my code : /gagoo/Rolan/file_name ?

 

(I also tried removing the "Rolan" from the URL : /gagoo/file_name. But it still does not work)

 

I assume the "Rolan" should NOT be there (since, the purpose of the Rule is to hide the "Rolan" from the URL in the browser, the same way the first Rule hides the "PHP" folder from view)

  • Author

 

If you think about your rewrite rule like this:

RewriteRule ^gagoo/$1/$2/?$       $1/Rolan/$2.php [NC,L]

Then entering '/gagoo/Rolan/file_name'

 

Should take you to:

 

/gagoo/Rolan/Rolan/file_name

 

​This is because $1 becomes Rolan and $2 becomes file_name.

 

I'm guessing that the rule that you're really looking for would be something like this:

RewriteRule ^gagoo/([^/]+)/([^/]+)/?$       $1/$2.php [NC,L]

 

 

I am still getting the 404 error

 

Should I write the URL with our without "Rolan" ?

 

/gagoo/file_name

 

or

 

/gagoo/Rolan/file_name ?

 

 

I tried both; neither are working;

  • Author

 

If your rewrite rule has been changed to the one I said above then enter it with 'Rolan'.

 

This will only work if you have a 'file_name.php' file inside a folder called 'Rolan' which is inside a folder called 'gagoo' at the root of your website. If you're using a Linux based server then they will be case sensitive too.

 

 

Perhaps, it's my fault for not having stated my entire file-structure from the start

 

I simply didn't think it was necessary, because, as I mentioned earlier : the second rule works perfectly.

 

So, I assumed that the same format would work with the third rule.

 

My file structure is as follows (from ROOT folder to file_name) :

 

www.example.com/Principal/Rolan/file_name

 

 

For the second rule, the file-structure is exactly the same.

 

www.example.com/Principal/Project/file_name

 

When I created the second rule (to hide the Project folder), I changed all my URLs in my php-code, to the following :

 

/Principal/file_name

 

And, it works. the "Project" folder is hidden from view

 

So, naturally, when I wanted to do the same for "Rolan", I thought the same principle applies.

 

 

But, I guess I was wrong.

 

So............using the new HTACCESS code you just gave me :

 

 

RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/$2.php [NC,L]

 

 

I guess that : I should replace "gagoo" with "Rolan"..............and then change all my URL (in the php files) to :

 

/Principal/file_name

 

 

Am I on the right track ? :(

Edited by newuserphp

  • 6 months later...

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.