LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Stange rewrite (https://www.linuxquestions.org/questions/linux-newbie-8/stange-rewrite-4175645625/)

Adirondacks 01-05-2019 09:32 PM

Stange rewrite
 
I am busy migrating code from my old MacBook to a new MacBook. Haven't looked at this code for a couple of years, and struggling to get it working again, even though it works on my old laptop.

I have a mod_rewrite that rewrites the home page from "http://local.mysite/index.php" to simply "http://local.mysite/"

Something isn't working correctly, so I renamed my .htaccess file to "xxx.htaccess" to disable it.

However, when I go to "http://local.mysite/index.php" it is still getting rewritten?!

I am wondering if something is filled out incorrectly in my httpd.conf file?

Would that explain the strange rewrite?

Adirondacks 01-06-2019 01:05 PM

Besides the .htaccess file, what would cause a URL rewrite when I go to "http://local.mysite/index.php"

Turbocapitalist 01-06-2019 01:17 PM

Have you checked the real configuration files for the web server? .htaccess is not the normal place for the redirects for most use-cases.

Adirondacks 01-06-2019 01:26 PM

Quote:

Originally Posted by Turbocapitalist (Post 5945350)
Have you checked the real configuration files for the web server? .htaccess is not the normal place for the redirects for most use-cases.

I have always done mod_rewrite in the .htaccess file. But again, I renamed the .htaccess file, so that isn't the issue.

So let me start over and explain what is happening in greater detail...

In DEV and using my IDE, I launch the "index.php" file. With the .htaccess file removed, I would expect my browser to load:
http://local.mysite/index.php

However, what is instead appearing is:
http://local.mysite/Users/user1/Documents/path/to/my/webroot/at/public_html/


There is no .htaccess present, so how is the rewrite happening??

Follow me?

The only thing I can think of is there is a problem in my httpd.conf file, although I swear this was all working last week?!

scasey 01-06-2019 01:33 PM

Sanity check: You are restarting the web server after each change, yes?

Have you tried searching httpd.conf and httpd.d/* for that string, or parts of it? Or for Rewrite directives?

What else have you tried? Are there any clues in the access or error logs?

Adirondacks 01-06-2019 01:41 PM

Quote:

Originally Posted by scasey (Post 5945352)
Sanity check: You are restarting the web server after each change, yes?

I did restart MAMP. Do I need to restart my Macbook as well?


Quote:

Originally Posted by scasey (Post 5945352)
Have you tried searching httpd.conf and httpd.d/* for that string, or parts of it?

I am comparing my httpd.conf file between my old macBook where things work and my new MacBook where things are broken.

Could this have to do with the virtual host I created?


Quote:

Originally Posted by scasey (Post 5945352)
What else have you tried? Are there any clues in the access or error logs?

I'm pretty weak on Apache, so not a whole lot.

I guess the main thing I did was to rename the .htaccess file to eliminate that the following mod_rewrite migt be the issue...
Code:

RewriteEngine on

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ $1 [R=301,L]


So something else is causing a redirect when my IDE tries to launch "index.php".

All of this is so frustrating!

Adirondacks 01-06-2019 01:47 PM

I looked in the log and it says...
Code:

[Date] [error] [client 127.0.0.1] File does not exist: /Users/user1/Documents/path/to/public_html/User

Not sure what the /User part is and whether or not the error message is getting truncated off or not?

As I mentioned in my last post, in my browser I see that it is putting in the entire file path to the webroot AFTER the webhost...

http://local.mysite/Users/user1/Docu...o/public_html/

Adirondacks 01-06-2019 04:06 PM

So now what?

scasey 01-06-2019 05:53 PM

Please stop bumping your thread. To do so without providing further information or clarification is against the LQ rules.

We're waiting for your responses to #5. What is MAMP? Is that the web server?

Adirondacks 01-06-2019 06:27 PM

Quote:

Originally Posted by scasey (Post 5945451)
Please stop bumping your thread. To do so without providing further information or clarification is against the LQ rules.

We're waiting for your responses to #5.

I responded to your questions several hours ago... (See post #6 and #7)


Quote:

Originally Posted by scasey (Post 5945451)
What is MAMP? Is that the web server?

Just like LAMP but for "M"acintosh...

Adirondacks 01-06-2019 09:17 PM

This is absolutely MADDENING!!! :banghead:

Everything has been working fine for the last week, and all of a sudden things are broken?!

Here is what I have dine so far...

First, I went into: /Applications/MMAP/conf/apache/httpd.conf


Here is what is in my httpd.conf the file including some changes...
Code:

ServerRoot "/Applications/MAMP/Library"

#DocumentRoot: The directory out of which you will serve your
# documents.  By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
# MAMP DOCUMENT_ROOT  !!! Don't remove this line!!
# DocumentRoot "/Applications/MAMP/htdocs"
#
# Added 2019-01-06
DocumentRoot "/Users/user1/Documents/path/to/public_html"


# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "deafult" to be a very restrictive set of
# features.
#
# Updated 2018-12-24
<Directory />
  Options Indexes FollowSymLinks
# AllowOverride Non
  AllowOverride All  #I think I mad ethis change to get PHPMailer v6 to work?
</Directory>


# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# belo.
#

# This should be changed to whatever you set the DocumentRoot to.

# Updated 2019-01-06
# <Directory "/Applications/MAMP/htdocs">

<Directory "/Users/user1/Documents/path/to/public_html">
  Options All
  AllowOverride All
  Order allow,deny
  Allow from all

  XSendFilePath "/Applications/MAMP/htocs"
</Directory>



NameVirtualHost *

# Added 2018-11-23
<VirtualHost *:80>
  DocumentRoot "/Users/user1/Documents/path/to/public_html"
  ServerName local.mysite
</VirtualHost>


I saved this, shut down MAMP, and rebooted my MacBook.

After starting up, and turning things back on, I went into NetBeans and launched "indoex.php" and it loaded my home page in Firefox just fine. (So the URL was: "http://local.mysite/indoex.php")


Then I went and renamed "+++.htaccess" back to ".htaccess".


In my .htaccess file, I stripped thingsd own to this...
Code:

RewriteEngine on

RewriteCond %{REQUEST_URI} ^.*/index\.php
RewriteRule ^(.*)index.php $1 [R=301,L]


Again, I shut down my MacBook.

After rebooting, I went back into NetBeans, and launched "index.php".

Unfortunately, this time my home page doesn't load and the address bar says:

http://local.mysite/Users/user1/Documents/path/to/public_html/



All of this has been working just fine for the last few weeks, and then a day ago I ran into this.

As far as I can recall, I don't believe I changed anything in my httpd.conf file or my .htaccess file.

I do recall tweaking my php.ini file, but can't think of anything that would have caused what i am seeing now?!

What in the world is going on??? :(

scasey 01-07-2019 12:03 AM

Please post
Code:

ls -l /Users/user1/Documents/path/to/public_html

Adirondacks 01-07-2019 12:23 PM

Quote:

Originally Posted by scasey (Post 5945525)
Please post
Code:

ls -l /Users/user1/Documents/path/to/public_html

Now we know why you "get the BIG BUCKS"... ;)


Here is the command I ran:
Code:

user1$ ls -l /Users/user1/Documents/30-ACME/10-INFORMATION TECHNOLOGY/++htdocs/01-ACME/public_html

Here are the results I got:
Code:

ls: /Users/user1/Documents/30-ACME/10-INFORMATION: No such file or directory

ls: TECHNOLOGY/++htdocs/01-ACME/public_html/: No such file or directory


user1$


Looks like that is the problem, right?


So how can I fix this issue and not mess up a filing scheme that took me a long time to come up with?! :confused:

scasey 01-07-2019 01:55 PM

Remove the space in the name of the directory...spaces in directory or file names on a Linux system are problematic. Replace with an underscore?
To execute the ls with the space, quote the path.

Adirondacks 01-07-2019 03:16 PM

Quote:

Originally Posted by scasey (Post 5945786)
Remove the space in the name of the directory...spaces in directory or file names on a Linux system are problematic. Replace with an underscore?
To execute the ls with the space, quote the path.

I thought operating systems evolved beyond spaces years ago...

Apparently this is still not true for maOC and Linux, huh?


*****
And as far as the problem I have been having, I wanted to add these comments to help you help me to troubleshoot...

If I get into my IDE and launch "index.php" I get the page not found issue described above. HOWEVER, if I go into a newly launched browser window, and type either of these URL's the page loads:

http://local.mysite/index.php

http://local.mysite/

http://local.mysite


So why do these URL's work when manually typed into the address bar, but if I try and launch my home page using my IDE, it fails?

Shouldn't the space in my directory structure break things every time?

Also, why didn't I have this problem last week or the week before, but now all of a sudden it is an issue? (I came up with my new folder paradigm back around Thanksgiving and things seemed to be working okay in my IDE?!)


All times are GMT -5. The time now is 11:53 AM.