I am currently building a website and it hasn't gone online, I am using wamp server 2.4. I need to remove the sub directories so as to not let out the structure of my directories, I have a test site with the following folders: includes and sub.
The links to be accessed are in sub so if the user clicks on a link that goes to sub/link.php, the url shows localhost/sub/link.php..I would like it to show localhost/test/link/ without the sub showing. So far I have googled mod_rewrite in Apache, learnt about it but still unable to remove sub-directory. All I have achieved is to remove the file extension(.php).
I have searched here on Stack Overflow but the answers are not helping maybe because they use online hosted websites. The link.php has no variables, it's a simple php file that could echo stuff but it's not using any GET/POST variables.
This is the html code, i have intentionally written one 't' in 'http'..though in the code it is two..
Link
RewriteEngine On
RewriteRule ^sub/(.*)$ /$1 [L,R=301]
Take a look at this site, it's hosted on wordpress and every link that you go to is shown without any subdirectories, it's just got one trailing slash after the url, is it possible to achieve that on apache?
http://www.afdar.com
Try this in your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/test/sub/
RewriteRule ^test/(.*)$ /test/sub/$1 [QSA,L]
It will rewrite URLs:
http://localhost/test/sub/link.php to http://localhost/test/link.php
http://localhost/test/sub/another.php to http://localhost/test/another.php
Related
i've a simple question but i cant find and answer for that:
i have in my site-root folder 3 subdirectory, in the first one i have a wordpress site, in the second and in the third two other sites but only for testing like this:
domain.com/wordpress/
domain.com/test1/
domain.com/test2/
Now i want when the user goes on the site to redirect him on my wordpress site but also when i want to access the other sites i directly put the correct address and go.
Right now i have the code down below but, when i try to connect to other folder he redirect me to the 404 wordpress page. How should i edit it to make it works?
I also want if its possible when i go on wordpress to not show the subdirectory in the url but only the domain:
NOT -> domain.com/wordpress/index.php
BUT -> domain.com/index.php
RewriteEngine On #created by aruba do not touch this file!
RewriteCond %{REQUEST_URI} !(.*)wordpress
RewriteRule ^(.*)$ wordpress/$1 [L]
I've set up a reverse proxy from my Windows server to a blog hosted elsewhere. All is fine except for the sitemaps.
The blog is on a subdomain: http://blog.example.com
The proxied domain is https://example.com/blog
As I'm using Wordpress, I've opted for Yoast SEO, but despite ARR doing the rerouting Google tools still complains about images it cannot access - on the origin domain. This is correct in one sense because I've added a second robots.txt on the subdomain, to stop duplicate content, but it doesn't make sense, in the sense that Application Request Routing should be hiding the subdomain. However, we all know that Google does what it wants to do.
I've found some code which I've added to my htaccess file:
# WordPress SEO - XML Sitemap Rewrite Fix - for reverse proxy
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ https://example.com/blog/index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ https://example.com/blog/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
I'm not sure whether it's doing anything at the moment because the image issue still exists, so my next step would be to try and redirect images to the new domain structure... and herein lies the problem - I know absolutely nothing about Apache stuff and definitely not apache rewriting.
What I need to do is redirect anything in the uploads folder, to a new absolute path
From, /wp-content/uploads/myimage.jpg to https://example.com/wp-content/uploads/myimage.jpg
Can anyone help with this final piece of the jigsaw?
Thanks in advance.
You can probably use something like the following in your .htaccess:
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
RewriteRule ^(.*)\.(jpe?g|gif|png|bmp)$ https://example.com/wp-content/uploads/$1\.$2 [NC,L,R=302]
A new client needs my help, their web developer messed up - built website on a draft/test server but forgot to block Google etc. I would appreciate help for the community here, I am not an expert with HTACCESS redirection.
As I said, another website developer setup the clients draft site on their draft server, its been there for months, however they forgot to hide it from search engines, so the content has been indexed by Google etc – this will trigger a duplicate content penalty if web put the new website live and the new website will be useless effectively.
I have access to the draft site / server and can modify the HTACCESS file, so when the new site goes live I would like to have the correct redirects in place. There are a few subdomains on the site (it's a multi language site), so it's a little tricky.
The website is built on Wordpress
The website structure looks like this on the test server. All files page names and file names are identical, just moving to a new server.
http://clientdomain.testserver.com
http://it.clientdomain.testserver.com
http://fr.clientdomain.testserver.com
http://es.clientdomain.testserver.com
http://de.clientdomain.testserver.com
http://ko.clientdomain.testserver.com
http://pt.clientdomain.testserver.com
http://ru.clientdomain.testserver.com
http://tr.clientdomain.testserver.com
http://cn.clientdomain.testserver.com
The redirects will need to go here:
http://clientdomain.com
http://it.clientdomain.com
http://fr.clientdomain.com
http://es.clientdomain.com
http://de.clientdomain.com
http://ko.clientdomain.com
http://pt.clientdomain.com
http://ru.clientdomain.com
http://tr.clientdomain.com
http://cn.clientdomain.com
The existing HTACCESS file on the test server looks like this
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
I would really appreciate any help on this.
There are some existing threads which contain all the pieces of the HTACCESS puzzle, but I am a little confused:
How can I redirect from one subdomain to another in .htaccess?
How can I redirect from one subdomain to another in .htaccess?
Kind Regards,
GG
If it was me I wouldn't bother messing around with redirects, get the urls removed from the index. Google will remove them with 24 hours, sometimes much quicker nowadays.
Add the development domain to your Webmaster Tools account and verify it. Then go to Google Index -> Remove Urls;
Just enter the the value / in the removal request which tells Google to remove every url in the index for that domain.
Then add a blocking robots.txt file to site root;
User-agent: *
Disallow: /
And what I normally do (this has happened a couple of times to me despite robots.txt and basic auth protection - git disaster/shenanigans) is prompt Google to reindex the site straight away. Go to Crawl -> Fetch as Google
Leave the input box blank so it fetches the whole site and just hit the Fetch button. When Google has fetched it click the 'Submit to Index' button.
You will be amazed how quickly this can happen these days, used to take weeks if you were lucky.
EDIT
And just to make sure this doesn't happen to anyone else finding this, the best way to stop it getting a dev site indexed isn't a robots.txt file or using Basic Auth via the .htaccess file (as previously mentioned it's easy to accidentally delete these). You should enable Basic Auth on the development site via the vhosts file.
Like it's not only for Google...
You can use this .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((?:..\.)?clientdomain)\.testserver\.com [NC]
RewriteRule ^ http://%1.com%{REQUEST_URI} [NE,L,R=301]
I have a problem:
I have to modify an application written in Zend 1 that was deployed to the domain root. now to test it the customer gave me a root subfolder called [domain]/social
When I run it, I have a lot of problem because all paths are like "/resource", but in this case the fiddler show me that the request look for [domain]/resource ad not for [domain]/social/resource.
It happens with script sources, ajax urls, hrefs...all!
Is there a way to fix the problem?
I am not quite familiar with Zend, but is there a main config file that sets the application root folder? (Like joomla) You can modify that if it exists.
Other option would be to preg_match or str_replace all instances of the domain name in the code ( like when moving a Worpress site) but you should definately do that with a sample content not couple hundred pages).
And here is a htaccess snippet as well:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/social/$1 [R=301,L]
Be sure to put the htaccess under the development folder not under the root, oterwise you're facing issues.
I suggest cheking for a config file first. Hope one of this helps!
I've inherited a PHP site from another developer and can't quite figure out what's going wrong. I'm suspecting some kind of rewrite rule somewhere but Im not sure where to look (or what specifically to look for...)
I've installed MAMP and it is working fine. I've got a couple sites running in the MAMP directory with no problems.
When I drop this site in and try to run the pages, I get pages with no CSS, JavaSCript or images. When I 'right-click' an image and open it in a new tab the image can't be found because the browser tries to go up one level in the directory to the MAMP directory in stead of looking in the site root directory.
Same thing on links to other pages, they all try to go up to the MAMP htdocs directory.
For example in htdocs I have the root folder of my site with the index page: 'htdocs/mysite.com/index.php'
On the page is a link to another page <li class="nav_company">Company
Clicking on 'Company' causes the browser to go up to the htdocs folder and look for the '/company/index.php', which of course doesn't exist.
Where do I go looking for the culprit on this? Is there a term or something I can search the site files for? I'm using dreamweaver and cold utilize the find and replace tool if I just knew what to go looking for...
Edit Here's the (sanitized) .htaccess file in the root folder of the site
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename\.com
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.sitename.com/$1 [R=301,L]
Redirect 301 /products/ http://www.sitename.com/plastic-handles/
Redirect 301 /plastic/index.html http://www.sitename.com/plastic/plastic.html
Redirect 301 /applicator/index.html http://www.sitename.com/applicator/applicators.html
Redirect 301 /company/index.html http://www.sitename.com/company/about-us.html
Redirect 301 /contact/index.html http://www.sitename.com/contact/contact-us.html
Redirect 301 /news/index.html http://www.sitename.com/news/news.html
Redirect 301 /trade/index.html http://www.sitename.com/trade/tradeshows.html
Thanks in advance.
It would seem that your assets and links are all pointing to the root so /contact/index.php will look at http://localhost/contact/index.php instead of http://localhost/mysite.com/contact/index.php
Look into setting up a virtual host to point to the new sites directory.
Otherwise it would be a case of changing all the links and assets to the full URL e.g. http://localhost/mysite.com/contact/index.php
Hope this helps
Edit: here is a guide to setting up a virtual host http://sawmac.com/mamp/virtual/
Edit 2: in response to your edit, .htaccess isn't going to make a difference as when you click a link or the server looks for an asset it's going to be looking in htdocs/. It will go no further and therefore will not reach your .htaccess.