Redirect parent not childs htaccess - .htaccess

In my magento module there is an extension.
Some urls like
http://www.domain.com/abc/p#abcs.html
http://www.domain.com/abc/p#xyz.html
etc
But when browsing http://www.domain.com/abc/p -> lead to blank page
I do not need http://www.domain.com/abc/p url
Is anybody help me
I want to redirect the url http://www.domain.com/abc/p to 404 page
without affecting its childs
ie
1. http://www.domain.com/abc/p#abcs.html
2. http://www.domain.com/abc/p#xyz.html
Points to its current position and
http://www.domain.com/abc/p to 404
Any help apperciated

Based on your comment it seems http://www.domain.com/abc/p#abcs.html shows proper content but http://www.domain.com/abc/p shows blank page.
In that case you can't do that via .htaccess because on server side URL will always be: http://www.domain.com/abc/p.
You need to put some custom Javascript in your page and redirect to some non-existant page (resulting in 404) by checking location.href using your Javascript.

Related

codeigniter making duplicating pages with #! include in link of each page

I have an issue on my website which is on CodeIgniter.
All links are making a duplicate copy of each with #! included in URL
for example
https://www.example.com/port-of-portsmouth
link to a page on my website which is duplicated like the below link
https://www.example.com/port-of-portsmouth#!
Both links have the same page content. How to get rid of this error to avoid content duplication
How to get rid of this error to avoid content duplication
You can't
Because # is used as a fragment identifier. For an example, if the URL is https://example.com/#data this means that open the example.com and jump to a specific section of the page with id"data"
See this URL, https://jestjs.io/docs/en/cli.html#cache
When you open the page, it jumps to cache section.
So, basically, your content is not duplicated, it's just opening the same page and then browser tries to navigate to id !, which might not be there and hence nothing special happens.

how to remove id of div in url with htaccess

I am having in an url the id of a div (#latest) like this at the end:
http://example.com/discussion/64/moderators-only#latest
http://example.com/discussion/32/bugs#latest
// and so on...
How can i remove the #latest in all these url's with htaccess?
You can't. Anything after the # is a URL fragment that the browser never even sends to the server. So the only thing the webserver sees is: http://example.com/discussion/64/moderators-only. So nothing in the htaccess or even in the apache config can do anything about those fragments.
You'll need to employ some sort of javascript or client-side solution if you want to remove it. But a better question is, do you need this in order to display the content correctly? If so, then how do you expect to display the content if this is gone?

hiding sub folders from url display

I have my pages categorized as below....
Main index.html is in the root, so this displays when the domain is entered into a browser.
May pages are categorized as below...
/Pages/Automotive/Ford/Mustang/*.html
/Pages/Automotive/Chevy/Camaro/*.html
/Pages/Automotive/Dodge/Charger/*.html
etc...
What I am looking for is a way to hide the subfolders from the url in the browser..
So, if a link, shortcut, or page is at the following:
/Pages/Automotive/Ford/Mustang/Main.html
The following is displayed in the url status bar on the browser...
/Ford/Mustang/Main.html
or even
/Mustang/Main.html
Basically masking the /Pages/Automotive/ Sub Directories.
And, if a this is entered in the browser:
/Ford/Mustang/Main.html
Then, the original page is still displayed at
/Pages/Automotive/Ford/Mustang/Main.html
Is this doable? If so how, I have looked into .htaccess, but I haven't found what I need..
I am also using 1and1 as my hosting company..

htaccess Redirecting or Rewriting to a form results page with variables intact

I am building a website which calls for a page selector on product search results, the page selector currently adds a forward slash and a number (representing the page) to the end of the current URL.
e.g. If I am browsing Washing Machines on "/laundry/Washing-Machines" and I click page 2 on the selector it takes me to "/laundry/Washing-Machines/2" and page 2 loads, this is working fine.
Now, the problem I am having...
I have a form in the sidebar where the user can filter Range Cooker search results by brand, fuel type, size and colour. The form gathers the products from the database that meet the search criteria, and displays the results along side the page selector.
If I leave the form values as default and submit the form I am presented with the results on "/cooking/Range-Cookers/Search?brand=0&type=0&size=0&colour=0" but when I click page 2 on the selector I am taken to "cooking/Range-Cookers/2" which presents me with a 404. If I add "&page=2" to the end of the original URL I am presented with page 2.
Since the page selector is a php include and works fine for every product except the results from my Range Cooker form, I would rather find a solution that leaves the selector php intact.
Is there any way I can add a redirect to .htaccess which would take a link from my page selector e.g. "cooking/Range-Cookers/5" and correctly apply it to the current URL with all form variables intact e.g. "cooking/Range-Cookers/Search?brand=1&type=2&size=0&colour=0&page=5"?
I have experience in HTML, CSS and PHP, but I am new to editing .htaccess and would appreciate any insight into how I can accomplish this. Thanks.
You cannot do this with .htaccess, because the information is not available, when the request hits Apache, or .htaccess for that matter.
When you click the link for page 2, the client requests the URL in the associated href attribute. It doesn't provide any other information available on the current page. If you want this information transmitted, you must modify the link for page 2 from
cooking/Range-Cookers/2
to
cooking/Range-Cookers/Search?brand=1&type=2&size=0&colour=0&page=2
when you deliver the page to the client. Same goes for any other information you need for following pages.

Multiple subdirectory error with mod_rewrite

I am trying to use mod_rewrite manually in joomla, and I have the following Rule:
RewriteRule ^test/(t1|t2|t3)-(.*).html$ /index.php?option=com_jumi&fileid=39&$1=$2 [L,NC]
So that I want the url
http://www.mysite.com/index.php?option=com_jumi&fileid=39&t1=foo
be displayed like
http://www.mysite.com/test/t1-foo.html
The rule works correctly, but when I am in the rewritten page the links like
http://www.mysite.com/link.html
or
http://www.mysite.com/xxx/link.html
become
http://www.mysite.com/test/link.html
or
http://www.mysite.com/xxx/test/link.html
respectively.
any suggestions?
thank you
You are using relative urls in your page. Your page contains a link like <a href="link.html">... and the browser makes the links relative to the current 'folder', namely "test", so when clicked the browser loads /test/link.html.
You should just use root-relative urls. So the link should become more like <a href="/link.html">.... The leading '/' makes the browser load the page relative to the root ("/"), not relative to "/test/".

Resources