.htaccess not every rewriterule works - .htaccess

I have the following .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
RewriteRule ^help$ /pages/help/index.php [NC]
RewriteRule ^help/search$ /pages/help/search.php [NC]
RewriteRule ^help/support$ /pages/help/support.php [NC]
RewriteRule ^help/bugfixes$ /pages/help/bugfixes.php [NC]
RewriteRule ^help/([a-z0-9-]+)$ /pages/help/category.php?cat_slug=$1 [NC]
RewriteRule ^help/([a-z0-9-]+)/([0-9]+)/([a-z0-9-]+)$ /pages/help/article.php?cat_slug=$1&art_id=$2&art_slug=$3 [NC]
The problem is the following:
When I go to localhost/help, it redirects to localhost/C:/server/htdocs, so I don't see the index page. The same happens when i go to localhost/help/bugfixes.
The other pages work perfectly! And untill today, /help and /help/bugfixes did also. :/
If I change ^help/bugfixes$ to ^help/bugfix$ (for example), the bugfixes-pages is showed again. If I change ^help$ to ^help/help$ (or any other thing), it also works for the index page.
I have literally no idea what could be wrong. I restarted apache already a couple of times, but still nothing... I didn't changed anything in the file for the last 2 days.
Can someone help me?
Edit: I also didn't changed anything in the php-files index.php and bugfixes.php

Try this htaccess :
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteRule ^ /%1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^help/(.*)$ /pages/help/$1.php [NC,L]
RewriteRule ^help/([^/]+)/?$ /pages/help/category.php?cat_slug=$1 [L]
RewriteRule ^help/([^/]+)/([^/]+)/([^/]+)/?$ /pages/help/artical.php?cat_slug=$1&art_id=$2&art_slug=$3 [L]

Related

.htaccess Rewrite QSA

So I have an htaccess file that I'm working on for someone, and I'm stuck on passing the URL arguments. Basically any and all arguments need to be passed, however I don't know all the queries, which is where I get lost and need help.
I've literally spent the past hour and a half digging through the internet and read about QSA's but have just gotten completely lost... Needless to say, I'm not well with htaccess files. Lines 1-23 are for something else related, but with the pages themselves.
Here's a few examples in case you're confused:
"/events/?query=dark needs to execute events.php?query=dark"
"http://mywebsite.com/authorize/?name=john would actually execute http://mywebsite.com/authorize.php?name=john"
Here's what I have so far, line 25 and down is just an official query I have atm.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ "domain"/$1 [R=301,L]
ErrorDocument 404 /404.php
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /events/?$ [NC]
RewriteRule .* /events.php [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /authentication/?$ [NC]
RewriteRule .* /authentication.php [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /databases/?$ [NC]
RewriteRule .* /databases.php [R=301,NC,L]
RewriteCond %{QUERY_STRING} name=(.*)
RewriteRule ^authorize/(.*) /authorize.php?name=%1

Using .htaccess to route friendly url

I am trying to route an url which is displayed as follows www.example.com/profile/1 to the following page with parameters www.example.com/profile?user=1. I have the following RewriteRule in my .htaccess, yet the routing is not working. Can someone tell me what I am doing wrong?
RewriteEngineOn
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/profile/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) /profile?user=$1 [L,QSA]
I have tried switching up the last RewriteRule to different URL's, but so far no luck. I am probably overseeing a small problem which someone can hopefully help me out with.
You need to allow for profile/\w+ as regex pattern to match /profile/123:
Options -MultiViews
RewriteEngineOn
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^profile/(\w+)/?$ /profile?user=$1 [L,QSA,NC]

.htaccess single variable url rewrite

I am trying to redirect http://test.pearlsquirrel.com/explore_all?u=hiphop to http://test.pearlsquirrel.com/explore_all/hiphop using htaccess. However, It keeps redirecting here: http://test.pearlsquirrel.com/explore_all/?u=site_error.php. I have looked all over Stackoverflow for the answer but I just can't seem to find it. I would really appreciate some help in fixing this problem, thanks!
Here is my .htaccess file
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) explore_all?u=$1 [L]
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} [^=]+=([^=]+)
RewriteRule .* /%1? [L]
Will map this:
http://test.pearlsquirrel.com/explore_all?u=hiphop
To this:
http://test.pearlsquirrel.com/explore_all/hiphop
Replace the corresponding code in your .htaccess file with this one.
I have not checked the rules in your .htaccess file.
OPTION
Now, if it is the other way around, which I think it is, and the idea is to map this incoming URL:
http://test.pearlsquirrel.com/explore_all/hiphop
To this resource:
http://test.pearlsquirrel.com/explore_all?u=hiphop
Replace the above rule set with this one:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .*/([^/]+)/?
RewriteRule .* http://test.pearlsquirrel.com/explore_all?u=%1 [L]

htaccess subdomain ssl wildcard not opening file

Ok So i have come across a problem with my htaccess and how to get it to work.
I have just purchased a ssl wildcard for my primary and sub domains.
I am with bluehost and they suggest adding this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomain/$1
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
At the moment all i have is this...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
and that works however, i cannot get it so that when i open the file, it just opens the file with no redirects...
So If i open sub.domain.com/file/fil1.js it will open the index.php which is what i do not want...
but if i do /browse or something like that it works...
Ok after much mucking around and playing around it was the file request which wasnt including the subdomain folder, which was causing it to not find the file location. So I managed to do a manual check for the file, and this is what i got. This seems to do exactly what i want. Im not sure if there is a more efficient way, but this is what it got.
#-------------------SUB.DOMAIN.COM---------------------
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{DOCUMENT_ROOT}/sub_folder%{REQUEST_URI} -f
RewriteRule . %{DOCUMENT_ROOT}/sub_folder%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
#--------------------------------------------------------------
instead of
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
You need to change your second rule so that it only gets applied when the request is ^(/)?$, then you need to duplicate what bluehost tells you to do. Essentially, replace:
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
With what they tell you to use:
RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomain/$1 [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^/?$ /sub_folder/index.php [L]

htaccess redirect from subdirectory to subdirectory

I'm trying to set up a local instance of a php site working in a server, in the "/" directory. My local instance will work in my development environment in a "/subdirectory/".
I'm trying to translate .htaccess to adapt to this, but I always get a 404. This is original .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
And these are my tries:
RewriteEngine on
RewriteBase /mylocaldirectory/
# Not in local! RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# Not in local! RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
Also
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)my-nice-url$ /index.php?p=ugly_url
Thank you
If i got you right, you want make a user friendly url, i do it like this:
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=$2 [L]
or
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=what-ever-you-need [L]
Hope it help you.

Resources