I am working with .htaccess using apache.
I want be able to type in a URL like this:
example.com/bob
and I want to rewrite the URL as
example.com/index.php?c=bob
I also don't want it to affect real files and to load them normally
example.com/account.php
In addition to all of this, I want to rewrite real files without the .php
example.com/account
So far I've been focusing on the index.php?c=bob task. I have this so far in my .htaccess
RewriteCond $1 !^(index\.php|account\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?c=$1 [L]
The work heavy solution I thought of is to list all of my files in line 1 above, I am looking for a more efficient way
Could you please try following.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?c=$1 [L]
It runs the example.com/bob correctly. I tried example.com/account.php and it acted as if 'account.php' is an input like 'bob'
@Jake, could you please do let me know if you have any other rules in your htaccess file?
I got the top comment mixed up and updated it. I don't have anything else in my .htaccess file. although example.com is a subdomain, sub.example.com
@Jake, ok so you mean these rules are working fine but you want to redirect request to a new sub domain name? If I am not wrong here that wasn't mentioned in question.
Your last answer update solved the problem it is working great now. Thank you