Totally lost on how to set up a .htaccess file, bunch of stuff and only been able to redirect and set index.
I have a site https://subdomain.domain.com/views/list.html and I want it to show up as https://subdomain.domain.comIve been able to hide the views/list.html from that main page with DirectoryIndex views/list.html but when i come back to it from within the website it still shows up as subfolder.Also is it possible for other subfolder files to not show up as subfolder but as something else? e.g. https://subdomain.domain.com/views/add.html show up as https://subdomain.domain.com/addproduct
Have you thought about trying PHP indexing? Make a folder structure and place the indexer in the correct folder. As for the subbing, it should be possible, least from what I recall.
Related
I'm working on a website on my local machine using PHP.
In my .htaccess file, I have the following line:
RewriteRule ^project-details/([a-zA-Z0-9-]+)/ project-details.php?pn=$1 [NC,L]
On the products page, I have the items containing a link like ./product-details/icecap-mouse249/...which the .htaccess file would in turn take and assign "icecap-mouse249" to the "pn" found at the end of the line: ?pn=$1 [NC,L].
When one clicks on the item, the person is then taken to the product details page. In that page, I have the following line:
$pn = $_GET['pn'];
This allows the URI to pull the 'pn' value and assign it to the variable $pn and utilize the variable to pull data from a database and display all the information of that particular product.
So, it works locally on my machine, but when I upload the files the page doesn't pull anything with $_GET[pn].
The product details page works because when I hardcode the value to $pn as in:
$pn = 'icecap-mouse249';
the page displays properly...pulling the data from the db.
I've done a phpinfo(); to see if the mod_rewrite is enabled, but the "Loaded Modules" section of the phpinfo page doesn't display. I did a CTRL+F to see if I could find the 'mod_rewrite' through the FIND tool, but nothing pops up.
The thing that trips me up is that it works locally on my machine.
I spent an hour with my host provider...and they weren't any help.
I hope I explained myself right and any insight would be greatly appreciated. Thank you.
You code is correct
Looks like you are dealing with special server configurations.
Try disabling multiview (add to .htaccess) which might been causing issues in 1and1, and also try separetly adding AllowOverride all.
Options -MultiViews
AllowOverride All
After uploading the file, when you click on your link, does the page displays any errors? Does it display anything at all?
You said, you have your links pointing to ./product-details/icecap-mouse249/. Make sure the page where you are putting your links is in the root diretory like:
http://example.com/page-with-links.php
But if the page with the links is outside the root directory it will not work.
http://example.com/xyz/page-with-links.php
This is because you are asking to look for ^project-details which means
http://localhost/project-details/any-string/
or
http://example.com/project-details/any-string/
How to prepare .htaccess file to block strange redirect...
When site is created in Cake, and we input address some like this: http://example.com/css, we are redirec to to http://example.com/app/webroot/css (403 Forbidden).
I think is the problem of .htaccess, but maybe no. The better solutions will be redirect to / or listing files if we can.
How solve this?
Cake expects http://example.com/css to redirect to http://example.com/app/webroot/css, which is where you should be keeping all your css files. You'll notice that doing things like echo $this->Html->css('style'); , the standard cake way for linking to a css style, it will create a link to http://example.com/css/style.css even though the file should be actually located in http://example.com/app/webroot/style.css. You do not want people to be able to look at http://example.com/css, since that is your css folder. If they can browse your file structure, they could potentially do bad things. So don't alter your .htacess file. As you said, whatever you're trying to do is most likely better done another way.
I have a website that's written using CakePHP. I've added some rewrite rules in the .htacces file to change the default urls to different ones (instead of /controller1/action1/parameter I have /some-string-about-controller-and-action/parameter, for example).
The problem is that now both the normal url and the nice one are available, and google seems to be indexing both, which is a problem. I'd like to only keep the nice one, which is the proper way to handle this so that it affects the google results as little as possible?
I don't know why you don't want to use cakes own routing (if you are having trouble doing what you want, you can accomplish what you want with a custom route class), then make sure that you redirect all relevant URL's in your .htaccess file to the desired URL using a MOVED PERMANENTLY redirect.
This way google will index the target url instead of the one that is undesirable. You are right to take offense to this, double indexing is a great way to harm your SEO rankings.
I have a website with multiple folders and I was trying to fix them in my .htaccess. After a little while, I have a big .htaccess with rules that conflicts.
Now every time I want to add a folder I have to add it to the .htaccess.
I did some research and I found out I can create symbolic link instead, so no more .htaccess
In both solution I have to create or modify something so for me its the same result at the end but is it a better practice to create instead symbolic link ?
Symbolic links are faster yes (like Aki said) but here's my thoughts on this.
if you have images, css or js files then you don't need to rewrite or create symbolic links. You can use the full URL (eg /images/...) or use a common domain like i.domain.com (or anything you want) and refer all your JS, Images and CSS there. Eg: i.domain.com/logo.jpg or js.domain.com/site.js.
This way, you never have to think about rewriting rules or create links you might forget one day.
This one is very easy to manage and maintain if you need to add images, change js or update your CSS since you only have one point of entry and automatically everything be updated.
use symblink, .htaccess has to be proccesed by apache whereas the symblink are proccess by the OS which is faster.
creating 100 rules vs 100 symblink, if the rule you looking for is at the last you will have to parse all of them then use the one you need.
I'm redeveloping a site (replacing it with one based on CodeIgniter), which is currently a horrid mess of repeated procedural code, however, it has good search engine rankings. Because of this, I need to keep the exact same URL structure.
The company has many different quote pages, which are all essentially the same - so I've produced one clean version which can be used everywhere.
The quote system is now in a folder called /get-quote, but due to the old URLs being required, that folder mustn't be visible anywhere.
I'd like the following to happen, but don't know how to:
A user accessing /insurancequote.php should (on the server) load the /get-quote/ directory (which in turn will load the default CI route). The Base URL in CI should be http://www.mysite.com/insurancequote.php (I'm able to do that bit), so moving to step 2 would result in: http://www.mysite.com/insurancequote.php/step2 (which would map to /get-quote/step2).
Secondly, a user accessing /brokerquote.php should show mysite.com/broker in the address bar (redirect?), but on the server access /get-quote/broker.
Thirdly, a user accessing one of many broker-specific pages, e.g. mysite.com/brokername1.php or mysite.com/broker/brokername2.php (yep, they are scattered all over the place! - but I do know where each one is) should show mysite.com/broker/brokername1 or mysite.com/broker/brokername2. On the server, /get-quote/broker/brokername1 or /get-quote/broker/brokername2 should be accessed.
I don't think what I've written is completely clear, so maybe sudocode helps:
If '/insurancequote.php'
Dont Redirect
Use '/get-quote/'
If '/brokerquote.php'
Redirect '/broker/'
Use '/get-quote/broker/'
// Do the following (manually) for each broker
If '/brokername1.php'
Redirect '/broker/brokername1/'
Use '/get-quote/broker/brokername1/'
If '/brokers/bname2.php'
Redirect '/broker/brokername2/'
Use '/get-quote/broker/brokername2/'
If '/mybrokerpage.php'
Redirect '/broker/mybroker/'
Use '/get-quote/broker/mybroker/'
Is this possible? If so, how would I go about doing it?
Thanks!
The risk you take is messing up your new clean code for historical reasons (and the guy coming next you will say, WTF, this is a mess!).
For me the right solution would be handling the url migration in apache and not in your application. Every refferenced url that you do not want to keep should get a 410 - Gone message (think about referenced images for example) and every referenced page which have a new matching page should get a 301 - moved permanently redirection on the right page. Then after some time as gone check the access log of your server, and if nobody checks the old url anymore then remove the rules.
If you know every old url and every matching url then use a matching url file (or hash file, faster) and manage the redirection 301 with rewriteMap. You can have a really big number of files in a hash file, the match should be fast. And it should be a temporary function, waiting for robots to fix the urls.