mod_rewrite not working the same in HTTPS as HTTP - .htaccess

UPDATED:
I currently have a .htaccess file in a folder called /pages/ that contains the following:
RewriteRule ^(.*)$ ../page_rewrite.php [L,QSA]
This then passes the path to page_rewrite.php when someone accesses www.something.com/pages/some/page-to-go/to/
This works perfectly when i access the site via
http://www.something.com/pages/some/page-to-go/to/
but i get a 403 when i go via https
https://www.something.com/pages/some/page-to-go/to/
accessing all php pages directly works just not the rewrittern URL.
Any ideas? i have been googling it but cant find what im looking for.

Related

.htaccess Redirecting url to a folder. Error on loading resources

I need to redirect from URL to a folder.
So, in the htaccess file:
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^(.*) http://www.example.org/portal/$1 [P]
But, when the portal app is requested it calls many .css .js .png files...
When these files are requesteds, the URL works like this:
www.example.com/portal/file1.css
www.example.com/portal/file2.js...
and I receive the 404(file not found)
It because when the app requests the files, the htaccess intercepts the call and reirect it to www.example.com/portal/portal/file1.css
So, i need when the exactly domain www.example.com is called, the rule redirect to www.example.com/portal. But when some resource of portal be called, the redirect must be do to www.example.com/resource. Internally it working like: www.example.com/portal/portal and i receive the 404 error
Help-me please.
Thanks
Probably you're using a relative path to your assets href="/portal/file.css" and the root url is www.example.com/portal
Try using the links without directory like href="/file.css"

Trying to rewrite a local url to another

I want to be able to do the following:
ReWrite /test -> /test.php
Also:
ReWrite /Test/test -> /Test/test.php
I want to be able to do this only for those mentioned urls. Also, I do not want direct access to .php urls. For example, if the user navigates to /Test/bla.php or any other links, he would be automatically be directed to the /index. The main reason I am doing this is that I do not want the user to know I am using .php. Here is what I tried:
RewriteEngine On
RewriteRule ^Test/test$ /Test/test.php
RewriteRule ^test$ test.php
ErrorDocument 404 /index.php
This works to some extent. I can navigate to /Test/test and it redirects me to /Test/test.php without issues. Though, if I do something like /test (from the root), I see the Test folder instead. Also, 404 does not work in this .htaccess above. I can navigate to any missing url and it complains that it is not there.
I am new to web hosting. So, I am kind of confused by the .htaccess.
Thanks for your time.

htaccess works with www.example.com but not example.com

I have installed Ghost, which needs nodejs to run. I'm doing this on an Apache Linux server via managed hosting. They kindly let me login with SSH access so I've been able to setup nodejs and Ghost using the standard installation instructions. I installed ghost to the root of my domain so in normal operation someone would go to example.com and it'll show them my blog. Well that's what I'd hoped.
However now when I've come to load Ghost in my browser I discover because I'm accessing it the way I am, and that Ghost doesn't do server configuration, I seem to need an htaccess file to be able to make the site reachable.
So, I have created this htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ http://127.0.0.1:65515/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:65515/$1 [P,L]
</IfModule>
With that saved to the root, if I go to example.com/ghost (the admin panel for Ghost) it works. Nothing wrong there, looks great. If however I try and visit the root, ie goto example.com, instead of showing me the index, it shows me index.js - that is, it literally loads the contents of Ghost's index.js file and displays it instead of parsing it and displaying the main index of the website.
IF however I go to www.example.com then it all works. So whatever the problem is it's because I'm not using www. in the domain.
I would prefer it to work both with or without the www in the URL though. I did try adding some solutions to redirect non-www requests to www.example.com to th ehtaccess but for some reason it still doesn't work (as in if I type example.com it doesn't redirect me to www.example.com).
I think maybe you should be using mod_proxy rather than mod_rewrite. At least, that's what I've used in the past. Apache will catch requests coming in on port 80 and then redirect them to port 65515 where your node server is listening.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
Like this:
ProxyPass / http://localhost:65515/
I figured it out. Wasn't anything to do with htaccess, or Ghost or nodejs or anything like it. No, instead the problem was the sodding server was caching the website. I discovered the setting to delete the cache and it all started working fine, so, this is now solved.

When trying to redirect using HTACESS, a string "/redirect:/" gets embedded with the url

I have setup two domains to point to the same hosting server. For eg: the domains be :
example1.com
example2.com
I have created a directory called 'home' in my root, and whenever the 2nd domain is accessed, it should get redirected to the home directory.
For eg: example2.com/post.php should get redirected to example2.com/home/post.php
I have done this by creating an htaccess file in my root directory with the following contents:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} example2.com$ [NC]
RewriteCond %{REQUEST_URI} !home
RewriteRule ^(.*)$ ./home/$1
This is working perfectly. Now, i have a second requirement where i need to redirect users to a php file (post.php) inside home directory whenever the user accesses the url example2.com/gallery/somestring.
So, i created a second htaccess file in my home directory and entered the following code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^gallery/([^/]+)$ post.php?post=$1
But, whenever i try to access the url example2.com/gallery/somestring, it shows a strange 404 Not Found error :
The requested URL /home/redirect:/home/gallery.html/somestring/somestring was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Here. "redirect:" string is getting concatenated to the redirected URL somehow.
Can any one please give me some idea as to why its happening ??
I solved this problem. I am sharing this if any one gets into this same problem and finds this post. The problem was that there was a file gallery.html in my root folder. This was causing this error. Just delete this file or rename the file to some thing else. Thats it :)

Custom URL rewriting not working in codeigniter

I use the code below in a Codeigniter htaccess file
RewriteRule ^([^.]+)-vacation$ /search?location=$1
When i access it with the url www.example.com/moscow-vacation,
it gives me a 404 error.
I have used the above htaccess code in a core php application. It works fine there.
Most likely, you don't have a search script. If the script is named search.php, you can use this slightly modified rule
RewriteRule ^([^.]+)-vacation$ /search.php?location=$1
If you have a controller named Search with a method location, you can either rewrite directly to
RewriteRule ^([^.]+)-vacation$ index.php/search/location/$1
or try
RewriteRule ^([^.]+)-vacation$ search/location/$1

Resources