0

Sorry first, I use google translate.

i have *.php

  • domainname.com/filename.php
  • domainname.com/file1.php?a=aa&b=bb
  • domainname.com/file2.php?a=cc

I want to change it to

  • domainname.com/filename (NO File extension)
  • domainname.com/aa/bb
  • domainname.com/cc

Now I'm writing only three conditions it not work Help me fix it. Thanks You.

<IfModule mod_rewrite.c>  
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)/(.*) /file1.php?a=$1&b=$2

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*) /file2.php?a=$1

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) $1.php [L]

 </IfModule>
IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • What happens when you use these rules? Does the wrong page get displayed? An error? Or just nothing at all? Have you tried making a simple rule that should match _everything_, to check that the configuration file you are editing is being used? – IMSoP Aug 22 '22 at 10:23
  • Also, see if any of the tips on this page is useful: https://stackoverflow.com/q/20563772/157957 – IMSoP Aug 22 '22 at 10:25

1 Answers1

0

Your implementation is nearly fine, I suggest just some small modifications:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^/?(.+)/(.+)$ /file1.php?a=$1&b=$2 [END]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^/?(.+)$ /file2.php?a=$1 [END]

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

However you did not say in your question what is the actual, specific issue you face with those rules. Which is why we cannot be sure if above code will actually solve your issue.

In case you have a general problem to get rewriting to work, then make sure these points as covered:

  • Make sure the rewriting module is actually loaded and activated inside the http server.
  • Make sure distributed configuration files (".htaccess") are considered at all by the http server.
  • Make sure your configuration file is located inside the DOCUMENT_ROOT folder specified in your http server's host configuration. Make sure it can be read by the http server process.
  • Closely monitor your http server's error log file.
  • Always make test requests from a fresh, anonymous browser window.
arkascha
  • 41,620
  • 7
  • 58
  • 90