I made my new template as a root directory with help of .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !new/
RewriteRule (.*) /new/$1 [L]
but I have an issue with that, all the products images are on the default public_html. how can I access that and if I want to upload product image then i get this error
Not Found
The requested URL /new/pimgs/ was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
please help in this issue.
You should make an exclusion to check if the URI is not starting with /pimgs/:
RewriteCond %{REQUEST_URI} !^/pimgs/
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1 [L]
Line 1: Test if the request URI is not starting with /pimgs/
Line 2: Test if the request URI is not starting with /new/
Line 3: If line 1 and line 2 are fulfilled, rewrite the URL to /new/$1
Related
I'm trying to do the following...
Original path that needs to be rewritten, renamed, or redirected:
http://www.example.com/_plugin/notifications/
to:
http://www.example.com/notifications/
via root htaccess file...Any help would be greatly appreciated!
=================================================================
This does not work:
RewriteEngine On
RewriteRule ^/_plugin/notifications$ /notifications [L]
This does not work either:
RewriteEngine On
RedirectMatch ^/_plugin/notifications$ /notifications/
This does not work either:
RewriteEngine On
RewriteRule ^notifications/(.*)$ /notifications$1 [R=301,NC,L]
=============================
EDIT
With the help of #Starkeen - I have a few follow up questions to this.
Is there a way to shorten the .htaccess file up though if lets say I
have multiple subfolders within the folder instead of writing that 1
condition and the 2 rules for each subfolder?
How would I allow subfolders of the subfolder to display? Currently it is throwing a 404 at me... :(
============
Still need help with follow-up question #1, but I believe I got question #2.
SOLUTION (I believe) to follow-up question #2:
RewriteCond %{THE_REQUEST} /_plugin/notifications/ [NC]
RewriteRule ^_plugin/notifications/(.*)$ /notifications/$1 [L,R]
RewriteRule ^notifications/(.*)$ /_plugin/notifications/$1 [L]
None of the rules you have tried are correct.
To redirect /folder/subfolder to /root/subfolder you need a permanent 301 Redirect rule something like the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} /folder/subfolder/ [NC]
RewriteRule ^folder/subfolder/$ /subfolder/ [L,R]
The above will redirect http://example.com/folder/subfolder/ to http://example.com/subfolder .
You will get a 404 error if the /subfolder/ doesn't exist in the root dir. To avoid the 404 error you can rewrite the /subfolder/ uri back to its original location /folder/subfolder/ using an internal Rewrite just bellow the first one
:
RewriteRule ^subfolder/?$ /folder/subfolder/ [L]
I'm trying to setup a new project structure. Due to some limitations of my cloud provider, I need to do some htaccess magic which I'm struggling with.
The project structure is as following
/docroot => Contains my Drupal installation
/docroot/frontend => Contains an Angular frontend
/docroot/pim => Is a symlink to /docroot.
What we need is that when we surf to example.com/pim that it redirects to the Drupal docroot /docroot. Since due to limitations of the cloud provider we can't put it in the /pim folder, they suggested to make a symlink.
Any other request to example.com should go to docroot/frontend.
So I've added the following code in my htaccess file
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/frontend.*$
RewriteRule !^pim($|/) http://example.com/frontend%{REQUEST_URI} [L,R=302]
Current behaviour is that all requests go to /frontend/index.php (I think the index.php comes from the .htaccess of Drupal, so the redirect is not done cleanely) While I would expect a request to example.com/test to direct to example.com/frontend/test
Also example.com/pim points to example.com/frontend/index.php instead of staying in the /pim directory
I've been able to fix it. :)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/frontend.*$
RewriteCond %{REQUEST_URI} !^/pim.*$
RewriteRule ^ frontend%{REQUEST_URI} [L,R=302]
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/frontend.*$
RewriteRule ^ %{REQUEST_URI} [L]
I want to set up a rule in my .htaccess file so that any url that is enetered, that results in a 404 because there is no such file, automatically re-directs to the home page of the site:
index.php
my .htaccess file looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^queenslandbeerweek.com.au$ [NC]
RewriteRule ^(.*)$ http://queenslandbeerweek.com.au/$1 [L,R=301]
ErrorDocument 404 /index.php
This causes the index.php file to show but is broken and leaves the eroneous URL in the address bar.
I have read in the answer to another post that it has something to do with passing the erroneous URL as a parameter, causing the page to not load properly, because the page calls data from a database and it is passing the bad URL as a parameter of index.php but there was no hint as to what the solution is.
What I would like to happen, is if an incorrect URL is typed into the address bar, or if a link is followed, to a file that does not exist, the completely forget about this file, drop everything, and go to the home page index.php.
index.php calls data from a database
Is this possible using a .htaccess file?
I have exactly the same problem with another of my sites.
Any help would be greatly appreciated.
Cheers, Al.
I dont think you can directly redirect an error document but you can catch nonexistent files and folders
!-f means not a file !-d means not a directory, $1 is whatever is in (.*) (the path in the url)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?errorurl=$1 [R=301,L]
ErrorDocument 404 /404.php
You can place the 404 error template anywhere you want. For example you could place all error messages in a folder called errormessages
ErrorDocument 404 /errormessages/404.php
Can't find this for the life of me. We have the indexes protected so if someone goes to CDNdomain.com/1/ they won't see anything unless they do CDNdomain.com/1/something.jpg. When they visit /1/ they are presented with a 403 Forbidden error. What I would like to do is when they are shown a 403 Forbidden error to instead redirect them to ourRealdomain.com.
Any ideas?
You can try something like this in the htaccess file in the document root of CDNdomain.com:
RewriteEngine On
# make sure this is the right host
RewriteCond %{HTTP_HOST} cdndomain.com$ [NC]
# make sure this is a request for an existing directory
RewriteCond %{REQUEST_FILENAME} -d
# redirect
RewriteRule ^(.*)$ http://ourRealdomain.com/ [L,R=301]
Note that this will also redirect /: http://CDNdomain.com/ to http://ourRealdomain.com/. If you want to avoid that, change the regex match from ^(.*)$ to ^(.+)$. If you want to put these rules in the vhost config for the CDNdomain.com, add a slash after the ^: ^/(.+)$.
I have a shared hosting in which I want to host several websites. To this end, and to keep things clear, I have redirected my primary domain (i.e. www.mydomain.com) to a folder (i.e. /mydomain.com/). However, I want to prevent direct access to this folder (www.mydomain.com/mydomain.com/) from the URL with a 404 error (not found).
This is the .htaccess in the root directory:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mydomain.com/0.1/$ [NC]
RewriteRule ^(.*)$ /mydomain.com/0.1/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
RewriteRule ^(/)?$ mydomain.com/0.1/index.php [L]
RewriteCond %{THE_REQUEST}% ^[A-Z]{3,9}\ /mydomain\.com/ [NC]
RewriteRule . - [R=404,L]
And this is the .htaccess in /mydomain/ with a bunch of rules for nice and tidy URLs.
RewriteEngine On
RewriteRule ^about/(.+) index.php?a=about&b=$1
RewriteRule ^services/(.+) index.php?a=services&b=$1
Right now this is the result:
Accessing www.mydomain.com shows the content in /mydomain/ as hoped. However, www.mydomain.com/mydomain/ is also displayed, ignoring the 404 rule, and creating another folder -whatever the name- without an htaccess DOES throw the 404.
I've been dealing with this problem for 5 days now and tried everything. At this point I don't know if the error comes from the root .htaccess or the folder's.
Thanks in advance.
PS: Just to be clear, I have no control over the httpd.conf file.
Notes:
I forgot saying that there is an additional folder inside /mydomain.com/ called /0.1/ for version control.
If a include "RewriteOptions Inherit" after "RewriteEngine On" in the /mydomain.com/0.1/ htaccess, I get a 500 internal server error.
Deleting the /mydomain.com/0.1/ htaccess file altogether will produce the desired 404 error for www.mydomain.com/mydomain.com/0.1/ and produce a 505 in www.mydomain.com
The R flag in rewrite rule should be something between 301 to 399 , so it can not be 404!!!
your rule should be like below:
RewriteCond %{THE_REQUEST} ^/mydomain\.com/? [NC]
RewriteRule (.*) throw_404.php [L]
create throw_404.php and to send 404 status code! and add L flag to your first rule for avoiding conflicting between that rule and mine!