URI is considered to be lowercased in htaccess. What might be wrong? - php

I have been battling with this problem for a while. Suppose I go to website.com/one/tWo. In PHP $_SERVER['REQUEST_URI'] is one/tWo. I thought this had something to do with Apache URL rewriting so I checked .htaccess and removed everything and only left:
RewriteEngine On
RewriteRule ^one/two http://www.gosomewhereelse.com [R=301,L]
To my surprise, when trying 'one/tWo', Apache actually redirects me to www.gosomewhereelse.com.
Just to be clear, there is no redirection that happens from 'one/tWo' to 'one/two'. The URL doesn't change in the address bar and it still has the uppercase character but it's still matching with ^one/two
I tried everything I could think of and couldn't find a solution.

This works:
RewriteCond %{REQUEST_URI} ^/one/tWo$
RewriteRule ^(.*)$ http://www.gosomewhereelse.com [R=301,L]
This also works:
RewriteRule ^one/t[W]o http://www.gosomewhereelse.com [R=301,L]

It turns out that it's not related to apache or PHP. The problem is from a third party software.

Related

Everything is correct but htaccess redirects?

I know this has been asked before but Ive not found one solution. I have the same source on same server but under another domain works fine. But for some reason on this domain:
I get too many redirects
Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://ropanel.pw/$1 [R,L]
if i go to https:// manually on my site without a .htaccess it works fine? I cant even to get it to work even if I use php to force the https://
I think you can change your rewrite rule to this.
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I don't think what you have is right.

Trouble mapping multiple subfolders to destinations in htaccess

We've switched servers and for whatever reason, our htaccess file isn't behaving the same way as it was on the other. I'm going to be the first to admit that I'm not an htaccess superuser, and I have no doubt the answer's probably looking me in the face, but literally an entire Saturday of searches hasn't fixed this. I have this filesystem:
When the domain is /category/subcategory/product/
It should rewrite to /category/product-details.php?p=product&s=subcategory
When the domain is /category/subcategory/
It should rewrite to /category-product-list.php?slug=subcategory
This seems simple enough, here's the same code we had been using for years. Note, we've commented out the first two RewriteRules regarding slashes and there was no change in behavior.
RewriteEngine On
RewriteBase /
# if folder does not end with a slash redirect to with slash
RewriteRule ^([-a-zA-Z0-9]+)$ /$1/ [L,NC,R=301]
#if it does not end with a slash e.g. rock-jewelry/some-piece, add the slash
RewriteRule ^([-a-zA-Z0-9]+/[-a-zA-Z0-9]+)$ /$1/ [L,NC,R=301]
RewriteRule ^category/([^/]+)/([^/]+)/?$ category/product-details.php?p=$2s=$1 [L,QSA]
RewriteRule ^category/([^/]+)/?$ category-product-list.php?slug=$1 [L,QSA]
When the domain is /category/subcategory/product/
It rewrites to /category-product-list.php?slug=product-details.php&p=product&s=subcategory
When the domain is /category/subcategory/
It correctly rewrites to /category-product-list.php?slug=subcategory
/category/ is an actual folder, and the only thing in it is product-details.php, there is no index.php file, the htaccess is supposed to rewrite to category-product-list if they're trying to access the index.
If we remove the category-product-list.php rule, the product-details.php rule DOES work. But isn't the L directive supposed to stop at the first rule? Why is the second still running? And how can I write a better way to accomplish this goal? Thank you very much, I'm pretty beat down on this problem at this point.
I have the same problem as you to understand the why of this loop... But it's like that.
You can add that before the last RewriteRule:
RewriteCond %{REQUEST_FILENAME} !-f
Or if you don't use dot in subcategory, you can use final RewriteRule:
RewriteRule ^category/([^./]+)/?$ category-product-list.php?slug=$1 [L,QSA]

URL Mod Rewriting

I am using codeigniter for my website, and before theres always that index.php? on my every url or links, for example
mysite.com/index.php?/about
Google has indexed all of my urls with that index.php? and I want to remove it and redirect it without that. I am having a problem rewriting the URL and redirect it to mysite.com/about and this what i have tried so far
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?(/[^\s\?]+)? [NC]
RewriteRule ^ %1/ [QSA,L,R=301]
what happened is, it only removed the index.php,
for example mysite.com/index.php?/about will turn to mysite.com/?/about I don't know how to remove that question mark,
I'm not good on mod_rewrite thanks in advance for the help.
I think you can improve the rules slightly.
RewriteCond %{REQUEST_URI}?%{QUERY_STRING} index\.php?\?.+
RewriteRule .*$ %{QUERY_STRING}? [R=301,L]
Essentially, you don't have to worry about the entire request line in %{THE_REQUEST}, which removes all the complicated regex. Also, the rule redirects to whatever is listed in %{QUERY_STRING}, and removes the query string.
I am not sure why you used QSA in the first place. I think that was part of the problem earlier. Just for an exercise, you can try removing QSA and see what happens.
You should try this one.
RewriteCond %{QUERY_STRING} ^/[a-z]+$ [NC]
RewriteRule ^/index.php$ %{QUERY_STRING} [NC,L,R=301]

Apaches mod_rewrite issues

I'm having issues with apaches mod_rewrite. I'm wanting to make clean urls with my php application but it doesn't seem to give the results i'm expecting.
I'm using this code in my .htaccess file:
RewriteEngine on
RewriteRule ^project/([0-9]{4})/([0-9]{2})$ /project/index.php?q=$1&r=$2 [L]
RewriteRule ^project/([0-9]{4})$ /project/index.php?q=$1 [L]
To make it so when I view, http://localhost/user/project/system, it would be the equivelant of viewing http://localhost/user/project/index.php?q=system
Instead of getting any results I just get a typical 404 error.
I've also just checked to see if mod_rewrite works by replace my .htaccess code with this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) http://www.stackoverflow.com
And it properly redirects me here, so mod_rewrite is definitely working.
The root path to my project is /home/user/public_html/project
The the url used to view my project is http://localhost/user/project
If anymore information is required let me know.
Thanks
If your .htaccess file is indeed located in the project/ subdirectory already, then don't mention it in the RewriteRule again. Remove it:
RewriteRule ^([0-9]{4})/([0-9]{2})$ /project/index.php?q=$1&r=$2 [L]
# no "project/" here
Rules always pertain to the current local filename mapping.
Else experiment with a RewriteBase.
You have [0-9]{4} in your regex which will only match numbers of 4 digits. "system", however, is not a number of 4 digits, and therefore does not match.
You can use something like [^/]+ instead.
RewriteRule ([^/]+)/([0-9]{2})$ /index.php?q=$1&r=$2 [L]
RewriteRule ([^/]+)$ /index.php?q=$1 [L]
Don't know if the second parameter should be a number with 2 digits or not.
Edit: I also added "user" at the beginning now.
Edit2: Okay, I thought you were in the root htdocs with your htaccess. So remove "project" and "user" if you are in "project" with the .htaccess.
You probably mean
RewriteRule ^/project/([0-9]{4})/([0-9]{2})$ /project/index.php?q=$1&r=$2 [L]
RewriteRule ^/project/([0-9]{4})$ /project/index.php?q=$1 [L]
The '^project' means "start of line is 'project'" but the start is a '/project', so you need to include the starting slash (i.e. '^/project...').
Sorry, missed the system bit (and the user bit). Was concentrating on the slash.
RewriteRule ^/user/project/([a-zA-Z0-9]*)/([a-zA-Z0-9]*)$ /user/project/index.php?q=$1&r=$2 [L]
RewriteRule ^/user/project/([a-zA-Z0-9]*)$ /user/project/index.php?q=$1 [L]
Should have you right.

Pretty URL’s and mod_rewrite

I can’t seem to make this work - and I’m pretty sure that the real problem is that I just starring myself blind on it, so I hope a pair of fresh eyes can help me out.
What I wan’t to do is have several applications attached to my system.
At this time, a website already exists in the root folder, but I wan’t some microsites/powerformats in a CI installation.
My mod_rewrite looks like this:
RewriteCond %{REQUEST_URI} ^/(powerformat1|powerformat2)/?$
RewriteRule ^(.*)$ powerformats/index.php/$1 [L]
Although, getting the CI index.php correctly, when trying to access example.org/powerformat1 or example.org/powerformat2 gives me CI’s 404 page.
It seems like whatever I try of rewrite rules I either get the 404 page or nothing at all.
Any insights?
-- EDIT --
What I believe is my problem is that CI actually gets the 'powerformat1' string passed as the first segment. That is what I need to avoid. But can't that be solved through mod_rewrite?
You could try link directly to the file with the appropriate query string instead
RewriteRule ^(.*)$ /powerformats/index.php?somequery=$1 [L]
(you may have to change the slashes, see below)
Or it may be this:
Accessing /powerformat1/
may be rewriting to
powerformats/index.php//powerformat1/
You could try
RewriteRule ^/(.*)/$ /powerformats/index.php/$1 [L]
or some other variation with slashes:
RewriteRule ^/(.*)/$ /powerformats/index.php/$1/ [L]
Did you miss RewriteEngine On ?

Categories