Link to home
Start Free TrialLog in
Avatar of Adebayo Ojo
Adebayo OjoFlag for Nigeria

asked on

Help with URL Rewrite

I have the below .htaccess for my website.
What I'm expecting is that when I login to my page, I suppose to have www.example.com/myusername to be generated from www.example.com/user.php?=myusername
But that doesn't happen automatically, rather I will see www.example.com/user.php?=myusername as my browser url. But if I edit the browser url by removing the user.php?=, leaving only www.example.com/myusername and then reload, I can still access the page.
Question 1: Is .htaccess rewrite not suppose to be done automatically? I would have expected that the browser url changed to the rewrite url by itself upon login.

When I access the url www.example.com/providers/myusername, if I point the mouse to any link on the web page, for example a link with this a tag  <a href="follow_page.php?u='.$log_username.'">, I expect it to show as www.example.com/followers/myusername at the base of the page based on my htaccess rules below, rather, it shows as  www.example.com/providers/follow_page.php?=myusername and when I click the link, it shows page not found.
Question 2: Why is it showing the original url instead of the rewrite url?
Question 3: Why is it adding providers to the url?

Options +FollowSymLinks 
RewriteEngine On
RewriteBase /
# Establish a custom 404 File not found page
ErrorDocument 404 /index.php

#Prevent directory file listing in all of your folder
IndexIgnore *

RewriteRule ^(.+)/(functions|php_includes|js|images|php_parsers|sample|style|uploads|user|jssocials-1.4.0)/(.*)$ $2/$3 [L]

# Stop infinite loop
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /user.php?u=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^followers/([^/]*)$ /follow_page.php?u=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^providers/([^/]*)$ /provider.php?u=$1 [L]

Open in new window


NOTE: In my httpd.conf file, I have:
#LoadModule foo_module modules/mod_foo.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule dir_module modules/mod_dir.so
#

Open in new window

Also
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
   # Options Indexes FollowSymLinks
     Options +FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

Open in new window

Avatar of David Favor
David Favor
Flag of United States of America image

Debugging rewrite logic can be complex.

Use the following command to trace your redirect chain, so you don't deal with any Browser caching problems either.

Always best to get complex redirects working outside a browser before tackling how Browser caching will effect redirects.

curl -I -L https://foo.com

Open in new window


Then proceed to enabling whatever level of redirect debugging is required in Apache to produce a log detailed enough to fix all problems.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.