I have .htaccess
file, profile.php
, index.php
and test.php
.
Let's say we have user john
If I will go to website http://example.org/john
, then I can see john
profile. But If I will go to index.php
or test.php
, then pages are with error 404 but shouldn't be. It seems that code from htaccess file is crashing every page.
How I can fix profile.php
and .htaccess
file to get:
http://example.org/john
doesn't exist, then show 404 error on the same page, if exist - show this profile test.php
) Code:
.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteRule ^([A-Za-z0-9\._\-]+)[^.]$ profile.php?user=$1 [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]
profile.php
<?php
if ($_GET['user'] != '') {
echo 'Showing user profile';
} else {
echo '404 error';
}
You cannot go from php execution back to apache.
You should swap the RewriteRules, so the file to php is performed first and the profile is done second.
Add L after your rule of no additional rewrite is required.
Look at http://php.net/manual/en/function.header.php to send a proper 404 response. Set 404 as the third argument.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.