Htaccess Mod Rewrite Not working for Pretty URL

I feel like such a tool for having to post this question, but for the life of me, I cannot figure out how to resolve my issue. (I've also read/tried previous posts but none have helped me)

I'm trying to turn https://mywebsite.com/article.php?slug=pretty-url to https://mywebsite.com/article/pretty-url

The problem I'm having is the $_GET method is not recognizing the slug, so it's giving me a 404 error. The slug is definitely in my database. I'm not sure why I cannot retrieve it.

Below is my htaccess code and my php code to call the page.

Htaccess Code:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

# Redirect www urls to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule (.*) https://mywebsite.com/$1 [L]

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://mywebsite.com/$1 [L]

ErrorDocument 404 /404.php

#Pretty URL for Blog
RewriteRule ^article/([0-9a-zA-Z]+) article.php?slug=$1


#Rewrite for certain files with .php extension
RewriteRule ^about$ about.php
RewriteRule ^services$ services.php
RewriteRule ^portfolio$ portfolio.php
RewriteRule ^blogs$ blogs.php
RewriteRule ^tutorials$ tutorials.php
RewriteRule ^contact$ contact.php
RewriteRule ^privacy-policy$ privacy-policy.php
RewriteRule ^terms-of-service$ terms-of-service.php
RewriteRule ^sitemap$ sitemap.php
</IfModule>

PHP Code on the article.php page:

//Get the blog. Only blogs that are published
$slug = $_GET['slug'];
$publish = intval(1);

//Query the database
$sql =  "SELECT * FROM blogs WHERE publish = $publish AND slug = $slug";   


//Execute the query
$stmt = $db->query($sql); 
$row = $stmt->fetch(PDO::FETCH_ASSOC);

Localhost Apache log entries that shouldn’t be there

I have tried to google this but all I can find are responses dealing with dummy requests which is not my issue

So in my apache logs there are some requests from 127.0.0.1 which I expect as I run PHP as well. However there are some entries that have me worried:

127.0.0.1 - - [31/May/2016:17:33:32 -0500] "GET /s/3453.mp4 HTTP/1.1" 404 499 "http://sportsthirsty.com/scripts/300_ad_mtf_desktop.htm?id=467582600" "Mozilla/5.0 (Windows NT 5.0; rv:21.0) Gecko/20100101 Firefox/21.0"

My concern is that someone is passing these requests through one of my PHP scripts. The only other possibility I can think of is that the IP is forged. Any idea whats going on here?

Localhost Apache log entries that shouldn’t be there

I have tried to google this but all I can find are responses dealing with dummy requests which is not my issue

So in my apache logs there are some requests from 127.0.0.1 which I expect as I run PHP as well. However there are some entries that have me worried:

127.0.0.1 - - [31/May/2016:17:33:32 -0500] "GET /s/3453.mp4 HTTP/1.1" 404 499 "http://sportsthirsty.com/scripts/300_ad_mtf_desktop.htm?id=467582600" "Mozilla/5.0 (Windows NT 5.0; rv:21.0) Gecko/20100101 Firefox/21.0"

My concern is that someone is passing these requests through one of my PHP scripts. The only other possibility I can think of is that the IP is forged. Any idea whats going on here?

Stop someone grabbing my data using php curl or something?

There's a lots of websites out there, sharing grabber scripts. I meant just install a script and you can have someones whole data. My personal site is based on Youtube API3 and our developer designed it to download videos from youtube.

But, the problem is, If someone wrote another script to stole my data, I mean grab my site's content with php curl or something, how can I stop him?

I can detect and block a single IP, but that's not the best solution. Please help me with some code's what we can put directly into our .htaccess file or somewhere to stop grabbing our content.

Redirect and modify query string

I've been struggling with some htaccess redirects. I just spent some time reading and searching on stack and couldn't get an answer that works with my scenario.

I want to redirect abc.com/knowledge-base/QUERY to xyz.com/display/GKB/New_QUERY.

Here is what i did:

RewriteCond %{QUERY_STRING} knowledge-base/(.*).html$ 
RewriteRule xyz.com/display/GKB/?/new_query

It didn't work. Any tip what I do wrong?

Redirect and modify query string

I've been struggling with some htaccess redirects. I just spent some time reading and searching on stack and couldn't get an answer that works with my scenario.

I want to redirect abc.com/knowledge-base/QUERY to xyz.com/display/GKB/New_QUERY.

Here is what i did:

RewriteCond %{QUERY_STRING} knowledge-base/(.*).html$ 
RewriteRule xyz.com/display/GKB/?/new_query

It didn't work. Any tip what I do wrong?

Find what script is running in php

The following Apache 2.4 processes seem to consistently be using up the CPU. While I appreciate that it tells me PHP is the command is there a way to see what script is running to eat up this much CPU.

Pid Owner   Priority    CPU %   Memory %    Command
17695 (Trace) (Kill)    seger   0     36.24   0.53  /usr/bin/php
17383 (Trace) (Kill)    seger   0     31.01   0.52  /usr/bin/php
17488 (Trace) (Kill)    seger   0     29.75   0.53  /usr/bin/php
17377 (Trace) (Kill)    seger   0     28.88   0.54  /usr/bin/php
17475 (Trace) (Kill)    seger   0     26.34   0.52  /usr/bin/php
17692 (Trace) (Kill)    seger   0     25.88 0.36    /usr/bin/php
18770 (Trace) (Kill)    seger   0     16.64   0.51  /usr/bin/php
1023 (Trace) (Kill) mysql   0     15.94   1.65

mvc .htaccess not understanding how to setup 1 level below root

Learning mvc here, so simple answers would help.

My site directory is 1 level below the actual web root, "mvc"

root/mvc

I have one .htaccess file in the mvc directory. root/mvc/.htaccess

<IFModule mod_rewrite.c>
RewriteEngine on
RewriteRule *$ webroot/ [L]
RewriteRule {.*} webroot /$1 [L]

In the webroot directory, root/mvc/webroot I have a second htaccess file

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %[REQUEST_FILENAME] !-f
RewriteCond %[REQUEST_FILENAME] !-d
RewriteRule ^(.*)$ index.php [PT, L]

And I also have an index.php in root/mvc/webroot,

<?php

define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));

$uri = $_SERVER['REQUEST_URI'];

print_r($uri);

Now according to the tutorial I should be able to type into a web browser url

http://localhost/mvc/controller/action/param1/param2

and index.php should echo

controller/action/param1/param2

except I'm getting a 404 error

The requested URL /mvc/controller/action/param1/param2 was not found on this server.

Clearly I'm not getting the fundamentals on the redirect of the web request, but have no idea why.

TIA folks, this one has me dazed and confused.

Oops there are closing tags on both the htaccess files.

mvc .htaccess not understanding how to setup 1 level below root

Learning mvc here, so simple answers would help.

My site directory is 1 level below the actual web root, "mvc"

root/mvc

I have one .htaccess file in the mvc directory. root/mvc/.htaccess

<IFModule mod_rewrite.c>
RewriteEngine on
RewriteRule *$ webroot/ [L]
RewriteRule {.*} webroot /$1 [L]

In the webroot directory, root/mvc/webroot I have a second htaccess file

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %[REQUEST_FILENAME] !-f
RewriteCond %[REQUEST_FILENAME] !-d
RewriteRule ^(.*)$ index.php [PT, L]

And I also have an index.php in root/mvc/webroot,

<?php

define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));

$uri = $_SERVER['REQUEST_URI'];

print_r($uri);

Now according to the tutorial I should be able to type into a web browser url

http://localhost/mvc/controller/action/param1/param2

and index.php should echo

controller/action/param1/param2

except I'm getting a 404 error

The requested URL /mvc/controller/action/param1/param2 was not found on this server.

Clearly I'm not getting the fundamentals on the redirect of the web request, but have no idea why.

TIA folks, this one has me dazed and confused.

Oops there are closing tags on both the htaccess files.

Hostname not working with Laravel (Lumen) installation on Vagrant

I'm able to access my Lumen installation on Vagrant via IP in the browser, but when I try accessing it through a custom hostname it redirects to http://mysite.dev/public and triggering a 404 error.

  • http://192.168.33.10 works as expected
  • http://mysite.dev redirects to http://mysite.dev/public and throws a 404 error: NotFoundHttpException in RoutesRequests.php line 443.

I'm on OS X running Scotch Box through Vagrant VM.

Any ideas? Here are (potentially) relevant files.

vagrantfile

Vagrant.configure("2") do |config|

    config.vm.box = "scotch/box"
    config.vm.network "private_network", ip: "192.168.33.10"
    config.vm.hostname = "scotchbox"
    config.vm.synced_folder "~/Documents/projects/mysite", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

end

/private/etc/hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
192.168.33.10   mysite.dev

/my_site/public/.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

Any help is appreciated :) Thanks!