Skip to main content
Removed ref to a porn domain.
Source Link
TRiG
  • 10.7k
  • 9
  • 62
  • 113

htaccess Use .htaccess to redirect all pages to subdirectory except root

enter image description hereI have these files in my My root, Inside pages i directory has the following structure:

/assets/ /pages/ /.htaccess index.pp 

Inside /pages/ I have phpPHP files for example projects.php For example,projects.php. I tried writing in .htaccess.htaccess rules to take the file for example xxx.com/projects toURL example.com/projects and open the file from /pages/projects.php/pages/projects.php and it worked with the following:

RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} . [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] # No file extension on request then append .php and rewrite to subdir RewriteCond %{REQUEST_URI} /(.+) RewriteRule !\.[a-z0-4]{2,4}$ /pages/%1.php [NC,L] # All remaining requests simply get rewritten to the subdir RewriteRule (.*) /pages/$1 [L] 

My problem here is that when iI go to the root xxx.comexample.com, instead of opening index.php itsindex.php it’s opening pagesthe /pages/ directory, but if iI go explicitelyexplicitly to xxx.com/index.phpexample.com/index.php it works. I dont

I don’t want index.phpindex.php to be shown in the url iURL, so I need to exclude the root from my rule and make it open index.phpindex.php while the urlURL stays xxxexample.com.com

htaccess redirect all pages to subdirectory except root

enter image description hereI have these files in my root, Inside pages i have php files for example projects.php, I tried writing in .htaccess rules to take the file for example xxx.com/projects to open the file from /pages/projects.php and it worked with the following

RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} . [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] # No file extension on request then append .php and rewrite to subdir RewriteCond %{REQUEST_URI} /(.+) RewriteRule !\.[a-z0-4]{2,4}$ /pages/%1.php [NC,L] # All remaining requests simply get rewritten to the subdir RewriteRule (.*) /pages/$1 [L] 

My problem here is when i go to the root xxx.com instead of opening index.php its opening pages directory but if i go explicitely to xxx.com/index.php it works. I dont want index.php to be shown in the url i need to exclude the root from my rule and make it open index.php while the url stays xxx.com

Use .htaccess to redirect all pages to subdirectory except root

My root directory has the following structure:

/assets/ /pages/ /.htaccess index.pp 

Inside /pages/ I have PHP files. For example,projects.php. I tried writing in .htaccess rules to take the URL example.com/projects and open the file from /pages/projects.php and it worked with the following:

RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} . [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] # No file extension on request then append .php and rewrite to subdir RewriteCond %{REQUEST_URI} /(.+) RewriteRule !\.[a-z0-4]{2,4}$ /pages/%1.php [NC,L] # All remaining requests simply get rewritten to the subdir RewriteRule (.*) /pages/$1 [L] 

My problem here is that when I go to the root example.com, instead of opening index.php it’s opening the /pages/ directory, but if I go explicitly to example.com/index.php it works.

I don’t want index.php to be shown in the URL, so I need to exclude the root from my rule and make it open index.php while the URL stays example.com.

edited tags
Link
MrWhite
  • 46.4k
  • 9
  • 67
  • 90
Source Link
Girl Codes
  • 388
  • 4
  • 19

htaccess redirect all pages to subdirectory except root

enter image description hereI have these files in my root, Inside pages i have php files for example projects.php, I tried writing in .htaccess rules to take the file for example xxx.com/projects to open the file from /pages/projects.php and it worked with the following

RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} . [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] # No file extension on request then append .php and rewrite to subdir RewriteCond %{REQUEST_URI} /(.+) RewriteRule !\.[a-z0-4]{2,4}$ /pages/%1.php [NC,L] # All remaining requests simply get rewritten to the subdir RewriteRule (.*) /pages/$1 [L] 

My problem here is when i go to the root xxx.com instead of opening index.php its opening pages directory but if i go explicitely to xxx.com/index.php it works. I dont want index.php to be shown in the url i need to exclude the root from my rule and make it open index.php while the url stays xxx.com