htaccess RewriteRule leaving the current directory scope - .htaccess

I'm creating a website based on wordpress on a hosting system (unfortunately not a dedicated system in this situation) and I am very limited in my configuration opportunities for Apache2.4.x / PHP8.
I was unable to convince my client to move to a more advanced environment, so I have to work with the given playground, as follows:
There is a website in /www/ which is linked to the domain (A-Record). There's an old man that maintains the current website until the new website is finished.
I am really not afraid that the old dev accesseses my development scope intentionally or uses PHP to do so to cause harm (he doesn't know PHP, he uploads locally generated HTML). He's an old man and I'm rather afraid that he accidently deletes, overwrites or moves my work while I'm working on the new website and I have to put it back together. He might be like "oh I don't know that folder" and it's gone.
My first task was to make and install certificates and enforce HTTPS, that worked pretty well so far.
Now I need www.domain.tld/dev/ to show the wordpress site, however the old developer can access the www scope and I really don't want him to mess with my code. He barely knows HTML.
In opposite to him, I have full access and can go outside of the /www/ directory, so I created a /wordpress/. Unfortunately I have no option to add a subdomain for that on said host, either.
Now here's where my problem and my approaches kick in, I am unable to move /www/dev/ to show the /wordpress/ content which is not inside of /www/.
Theoretically I would do this on my root server but my client wants the website development to happen in his webspace. That's a bit strange but no subject to change. Just take that as given fact please.
So my htaccess rules for this are not doing anything and I can not spot what's wrong.
(Note: The .htaccess is laying inside of /www/)
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^domain.tld [NC]
RewriteRule ^(.*)$ https://domain.tld%{REQUEST_URI} [R=301,L]
#RewriteBase /
#RewriteRule ^/dev /is/htdocs/wpCUSTOMERIDSTRIPPED/wordpress [QSA]
#RewriteRule ^/dev/(.*) /is/htdocs/wpCUSTOMERIDSTRIPPED/wordpress/$1 [QSA]
RewriteBase /is/htdocs/wpCUSTOMERIDSTRIPPED
RewriteRule ^/www/dev /wordpress [QSA]
RewriteRule ^/www/dev/(.*) /wordpress/$1 [QSA]
Thank you alot in advance.
Note: The search function did not help me further as I am moving outside of the scope of the active directory.

Related

Why htaccess not working for mobile browser?

I have website (mzadkm.com) try to RewriteRule short url to app.php page .
So if user browse "mzadkm.com/app" will show "mzadkm.com/app.php" page
RewriteRule ^/app /app.php [L,R=301]
It's work on Computer , but on mobile browser give me 404 page
Any ideas
That probably is what you are looking for:
RewriteRule ^/?app /app.php [L]
The documentation clearly says, that the pattern in a RewriteRule get's applied to the relative path of the request if the rule is implemented inside a distributed configuration file. That means you actually want to match the path app and not /app here. Which is why your rule did not get applied. The ^/?app is a variant to accept both path notations, relative and absolut, which means the same rule can get implemented in the central configuration or likewise in a distributed configuration file (".htaccess").
I took the liberty to also remove the external redirection you showed ("R=301") since that most likely is not what you want, according to the phrasing of your question. Instead you want an internal rewrite .
You need to take care however that you do not implement a rewriting loop. Which would result in failing requests and an "internal server error" (http status 500).
One approach would be that:
RewriteEngine on
RewriteRule ^/?app$ /app.php [L]
Here another one:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?app /app.php [L]
Why things looked fine on your computer, but not on a mobile browser is unclear. Since the same rules get applied and the requests look the same there has to be another reason for that. I suspect you looked at a cached result of a previous attempt somewhere. Remember to always use a fresh anonymous browser window when testing. And to check the response you receive back inside your browsers network console.

How do i change the .htaccess on cPanel's Online File Manager (ByetHost)?

I'm using ByetHost as my website's FTP service, i configure everything (besides uploading the stuff) via ByetHost's Vista Panel, which has a Online File Manager where i presume i could edit the .htaccess.
However when i arrive at the File Manager, i can't seem to find the .htaccess file, and there is also a lack of a Settings button too.
Here is what the File Manager looks like: (the htdocs is where all my website's stuff is at)
I know ByetHost and/or whatever this unknown File Manager is not well known, but i'd like to ask anyways if there's anyone that could help me on how to configure my .htaccess. I would appreciate it.
I had this issue too, and couldn't find any settings or otherwise.
So what I simply did was:
Just created a new file and named it .htaccess!
And a quick test, I put in the following to allow access to my .html pages without actually typing the extension:
RewriteEngine on
RewriteRule ^(.+)\.html$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ /$1.html [NC,END]
And it worked successfully.

Joomla - htaccess Redirects Error

I've had a Joomla 2.5.28 site for quite a while now and recently changed hosting providers. On the new server I managed to get Joomla updated to 3.2.7 and get it to run normally.
Now for the tricky part:
On my previous hoster I had a second installation being kind of the gateway to the other site. It just lets you select language and that's it.
My domain is www.cyclingtoserve.at with Joomla Main being /joomla and Joomla portal being /3.1
I figured by adding a REDIRECT rule from / to /3.1 I could get the portal up and running again. Sadly not.
This is what I get:
I thought I could undo this by deleting the .htaccess file. The problem lives on though.
I've tried just about everything. Help is VERY MUCH appreciated!
Edit01: A bit more info may be interesting.
The Joomla install is in /joomla while the other page is in /3.1
The .htaccess file however was in the root directory.
Edit02: I have managed to remove the wrong redirection. Question is: What is the correct way to redirect people from www.cyclingtoserve.at to /3.1? (without it showing up in the address)
Edit03: Here is a graphical representation (FTP) of the folder structure.
ftp
In order to avoid the redirect loop, you need to first check to see if your are already in the /3.1/ folder. Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/3.1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://%{HTTP_HOST}/3.1/$1 [L,R]
Sadly I've had to give up using .htaccess for the redirection.
I would have loved the recommended way (and still would like to know how).
Solution:
index.html in root has the following lines:
<frameset rows="100%" frameborder=0 framespacing=0 border=0>
<frame src="http://cyclingtoserve.at/3.1/" name="Content" noresize>
<noframes>
It may be the quick and dirty way of dealing with this issue, but it works.
If you can reproduce the same results with .htaccess, I'd love to tag it as an answer.

htaccess redirect of root domain, not subfolders with url masking

I am trying to do the following -
Redirect just the root domain to a different domain.
The redirect needs to be masked so the user still thinks they are on the url they typed.
Existing subfolders should still work with the existing root domain.
For example-
I have an installation using www.currentsite.com which has lots of subfolders for example www.currentsite.com/store
I want to redirect just the root of www.currentsite.com to www.newsite.com but want the browser to still say www.currentsite.com.
If the user goes to www.currentsite.com/subfolder I still want that to work with the original installation.
I have the following which seems to be handling redirecting just the root fine but does not mask the url...
RewriteEngine on
RewriteCond %{HTTP_HOST} www.currentsite\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://www.newsite.co.uk/ [L,R=301]
Any help id appreciated.
For what you call "masked" the usage of apaches proxy module makes most sense:
ProxyPass https://www.currentsite.com https://www.newsite.co.uk
ProxyPassReverse https://www.currentsite.com https://www.newsite.co.uk
It maps one base url to another one and takes care to transparently and reliably rewrite all contained references.
The proxy module can also be used by RewriteRules, the P flag does that. But in the end it comes out itself and the above, direct usage is more transparent and less complex.
Here is the documentation, as typical for the apache project it is of excellent quality and comes with lots of good examples: https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

CakePHP: Can you globally modify all links to point to another directory?

My CakePHP app lives inside a subdirectory to keep it from crashing into a Wordpress installation that powers part of the website:
example.com/ <--root
/_wp <--Wordpress installed here
/page1
/page2
/_cake <--CakePHP installed here
/page3
/page4
To maintain consistency, I'm using mod_rewrite rules to rewrite URLs from example.com/_cake/pageX to example.com/pageX etc. This basically works, but CakePHP still creates links with /_cake/pageX. So if a user hovers over a link, the "_cake" will show up in the bottom of the browser and of course in the source code.
Is there a way to configure CakePHP to think it's actually in the site root so it creates the desired URLs for links etc?
I haven't found a way to configure CakePHP the way you want.
If you create your links with HtmlHelper::link or Router::url, you can add a member $url['base'] = false to the $url array argument. This prevents the _cake prefix being inserted in front of the URL.
As an alternative, you can create your own link() or url() function, which calls HtmlHelper::link and always adds base = false.
For this to work, you must also have a .htaccess in the document root, which rewrites the requests to their real destination
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /_cake/$0 [L]
You must also pay attention to requests destined for the _wp directory.

Resources