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.
Related
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]
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
I am unable to access my WordPress site URL, it redirects like
http://www.mydomain.net/wp-login.php?redirect_to=http%3A%2F%2Fmydomain.net%2Fmydomain.net%2Fwp-admin%2F&reauth=1
but it shoud redirect to
http://www.mydomain.net/wp-login.php?redirect_to=http%3A%2F%2Fmydomain.net%2Fwp-admin%2F&reauth=1
I believe the problem is with .htaccess file as I am rewriting the path of folder like
public_html/mydomain.net
instead of public_html as this domain is primary domain of cPanel but to avoid confusing, I created a directory and rewriting path using .htaccess.
There is nothing wrong with WordPress. In settings>general both the URLs set to mydomain.net
.htaccess code is Placed in Public_HTML
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.net$
RewriteCond %{REQUEST_URI} !mydomain.net/
RewriteRule (.*) /mydomain.net/$1 [L]
I had a similar problem after changing the root directory of my blog (before migration) and trying to coming back... Changing the data in my DB was not working for me.
I still did not figure out why but I had a "page not found" when I tried to access categories, tags,... and even on the home page. Links to articles worked correcly and the administration page was not accessible (wp-admin rewritten twice in the url).
These actions solved my problem:
Edit the wp-config.php file.
After the "define" statements (just before the comment line that says "That's all, stop editing!"), insert a new line, and type:
define('RELOCATE',true);
Save your wp-config.php file.
Open a web browser and manually point it to wp-login.php on the new server.
I had to change the value of the root directory in the administration page (after these actions gave me back the access to it).
Check http://codex.wordpress.org/Changing_The_Site_URL#Relocate_method for more info.
Alright I have already contacted BlueHost Support and they couldn't figure out how to fix this issue. I've also tried to use cpanels 301 permanent redirect but that doesn't work so I decided to give it a whirl on here.
I host with BlueHost.com if you haven't caught that by now. The file structure is as follows:
public_html/
directory1/subdomaindirectory
directory2
directory3
I have my main website in my root (public_html). Then I have to create new directories and assign the url to that directory. So essentially if you typed in www.maindomain.com/directory1 it would show the website in the directory. I would like to modify the .htaccess to redirect that to it's original domain so www.maindomain.com/directory1 would go to www.directory1.com
The same for subdomains. I created subdomain.directory1.com and pointed it to public_html/directory1/subdomaindirectory and if you go to www.directory1.com/subdomain it pulls up the site.
I realize theoretically it's the same thing but it bugs me that you are able to pull up a website like that.
Is there anyway to modify the .htaccess to fix this issue?
In.htaccess you could do it like this
RewriteEngine On
RewriteBase /gorbox
RewriteCond %{HTTP_HOST} ^www.gorbox.com$ [NC]
RewriteRule ^support$ http://support.gorbox.com [L,R=301]
Put this in the .htaccess file that resides within the root folder of www.gorbox.com
I have recently assisted in moving a website from a pure development domain to a live site where there used to be a site handled by another CMS system than what we are currently using. Current system is Joomla, but I don't think it matters much for my question.
So with the current site the URLs are rewritten from the standard Joomla format to be stripped of index.php and .html suffix is added in the address, meaning that URLs look like this:
http://example.com/folder/page.html
In the old site handled by another CMS systems the URLs had the following structure:
http://example.com/side.php?id=1
We are a social organisation with many sites linking to us - also quite a few that we are not even aware of - so the problem I need to handle is this: I need to redirect all these dead links on other sites so that they simply get pointed to the root of our site.
Can anyone please explain to me how to make .htaccess redirect as follows:
/side.php?id=* to root of example.com
In this case I mean the * to mean any number as there are naturally alot of pages with different IDs.
It is not of any significance to me if they point at a www. prefix or not.
Thanks in advance for your help, I hope I have not asked a question that's been answered before but my experience with .htaccess is very limited and having searched and tried different solutions didn't do it for me.
In .htaccess in the root folder, add the following:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=\d+
RewriteRule ^side\.php$ http://%{SERVER_NAME}/ [R=301,L,QSD] #Remove the ",QSD" for Apache <2.4.0, or to keep the query string.
The R=301 will tell browsers/search engines that the page has permanently been moved.
A rule like this should work:
RewriteCond %{HTTP_HOST} .*
RewriteCond %{QUERY_STRING} id=\d+
RewriteRule ^side.php http://example.com [L,R=301]
This will redirect externally, with a HTTP 301 response (Moved Permanently)
What you need here is some 301 Moved Permanently responses to let browsers and search engines know that you're moving pages to a new location. Instead of using a mod_rewrite to redirect all requests to this side.php page, I would analyze each page of your old website and determine where all the content has been moved. Armed with this, use the htaccess Rewrite directive to inform browsers of individual pages being moved
Redirect 301 /side.php?id=123 /about_us.html
Redirect 301 /side.php?id=456 /contact_us.html
I recommend this method because it redirects those who navigate to the outdated page to the new page that has similar content to the old one they were requesting instead of just redirecting them all to your home page.