Change Link href from .htaccess [closed] - apache

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I want to change url used in href from .htaccess. As I am working in a existing project so I don't want to change the href from 46 files. Is there any way? For instance the code below is in the html file.
<link href="http://localhost/example.com/UK/styles/style.css">
I want to change it to http://localhost/example.com/styles/style.css from .htaccess
Here, my absolute domain is http://localhost/example.com
And my .htaccess is in the document root

.htaccess doesn't actually "change url used in href", but it allows you to internally rewrite a request from /example.com/UK/styles/styles.css to /example.com/styles/styles.css. The user still sees /UK in the URL, the URL is unchanged, but the file that receives the request is.
For example, at the top of the .htaccess file in the "document root". (ie. at http://localhost/.htaccess) you can do something like the following:
RewriteEngine On
RewriteRule ^(example\.com)/UK/(styles/style.css)$ $1/$2 [L]
For a more general "any URL" solution:
RewriteRule ^(example\.com)/UK/(.*) $1/$2 [L]
$1 and $2 are backreferences to the captured subpatterns in the preceding RewriteRule pattern.
Reference:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Related

How to make a webpage without .html in your URL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Like the title says I want to visit my webpage without typing .html after the webadres.
So for example I have to type this at the moment: www.webadres.com/webpage.html
Now I want to change that into www.webadres.com/webpage
I've already tried some things like deleting the .html extension on the end of my file but that (of course) doesn't work.
I see I missed something:
I don't really understand it but I got a folder (called "cgi-bin") with a .htacces file.
In the .htacces file is the following text:
Options -Indexes +ExecCGI AddHandler cgi-script .cgi .pl
I want a webpage like this
www.example.com/webpage
Instead of
www.example.com/webpage.html
I didn't know about all the server side technologies but now it seems I have Apache.
If it didn't worked out you could also check out these:
How to remove .html from URL
ReWrite rule to add .html extension
create a htaccess file which has the name of .htaccess, then place the following code
RewriteEngine on
RewriteRule ^yourPage$ yourPage.html [NC,L]

The Redirection of Multiple Parked Domains doesn't Work with Filename [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
My problem seems simple to me but I cannot find a simple solution. Here goes: I have one main domain, and multiple domains pointing to that main domain. To avoid duplicate content I'm trying to redirect all "secondary" or "parked" domains to my main domain so that it resolves to this:
www.parkeddomain1.com => www.maindomain.com
www.parkeddomain2.com => www.maindomain.com
www.parkeddomain3.com => www.maindomain.com
And so on...
Now I have found this htaccess code that is sort of a catch-all solution (which I would prefer):
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.maindomain.com$
RewriteRule ^(.*)$ http://www.maindomain.com/$1 [R=301]
So this code works when I'm dealing only with straightforward parked domains, not with parked domains with subfolders or subfiles. So:
www.parkeddomain1.com => www.maindomain.com
redirect works fine here but when I add a subfolder this happens:
www.parkeddomain1.com/subfolder/ => www.parkeddomain1.com/subfolder/
when what I'm looking for is:
www.parkeddomain1.com/subfolder/ => www.maindomain.com/subfolder/
All this in order to avoid the duplicate content problem with search engines.
Thanks to all for any answer that would guide me to a solution.
Cheers!
If the questioner starts rewrite ruling with [R=301] 301 redirect, a.k.a. “Permanently Redirect”, and then he try to view his URL www.parkeddomain1.com/subfolder/ but the result of the rule wasn't what he want, then even he try to change the redirecting rule, his web browser will always redirect that URL into the first URL where it redirecting with [R=301] flag. Because once the browser has been redirected permanently to the wrong address, even how many times you edit the rule, your browser will still be redirected to the old address, that's a browser thing, and you may even go on to fix the rule, and then change the rule all over again without ever knowing it. Changes the 301 redirects in your browser can take a long time to show up.
The solution is to restart the web browser, or use a different one. So, if you're testing, it's better to use a [R] flag instead of [R=301] flag. And when you are 100% sure that the rule does exactly as it's expected to, then switch it to [R=301] flag. Or else, this question belongs to Server Fault.
If your sole aim is to appease search engines, you can alternatively specify a canonical URL which tells search engines the definitive URL for a piece of content. So even if the same content is served by several different query-string variants, or several different domains, the canonical URL will tell the search engine that these are just alternatives to the one true URL.
See the Google Webmaster Central Blog about Canonical URLs for the details.
Try adding the "L" after 301
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.maindomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

url rewrite `/abc/products-` to `/def/products-` [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have many url links in /abc/ sub-directory, like
http://www.domain.com/abc/products-12345
http://www.domain.com/abc/products-23456
http://www.domain.com/abc/products-34567
http://www.domain.com/abc/new-items
Now I want to url rewrite /abc/products- to /def/products-
http://www.domain.com/def/products-12345
http://www.domain.com/def/products-23456
http://www.domain.com/def/products-34567
http://www.domain.com/abc/new-items
My code in .htaccess, but nothing changed. How to rewrite in this case? Thanks.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^abc/products-(.*)$ /def/products-$1 [L,R=301]
</IfModule>
As you can test on this simulator the rules should work.
The most probable problem you are facing should be:
The global configuration does not allow for .htaccess overwrite
.htaccess is not readable for apache user
You have no mod_rewrite active on this apache server, thus no trigger to <IfModule> directive.
Best troubleshooting option would be trying a redirection of all page to a static page. If this does not work, look for a configuration problem.

Problem with yourls.org redirects on windows 2003 with ISAPI rewrite [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've setup a yourls.org (URL shortening service) on a windows 2003 VPS server I have, using ISAPI rewrite. I already have ISAPI rewrite installed and working with Wordpress, so I know that is working. I have used the rules suggested from the page:
http://code.google.com/p/yourls/wiki/htaccess
In my ISAPI rewrite, but the redirects are not working. The page is looping, trying to redirect to itself.
I'm not familiar with Rewrite rules so any help would be appreciated. The rules I've applied are:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/|\.php|/[^.]*)$ [NC]
RewriteRule ^(.*)$ /yourls-loader.php [L]
I added the third conditional line based on something I found in the wiki of the application.
If anyone could shed any light on why this isn't working, I'd appreciate it.
T
Ok, this took me all day, but I got it working. For anyone interested, there was absolutely nothing wrong with the ISAPI rewrite. The problem was in the code. In a file called yourls-loader.php, there's a line that checks the url, deconstructs it and reconstructs it. The problem is that it always forces the new url into https. If you've no security cert on your server it won't work!!!
//$scheme = ( isset($_SERVER["HTTPS"]) ? 'https' : 'http' );
//$request = str_replace( YOURLS_SITE.'/', '', $scheme . 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$request = str_replace( YOURLS_SITE.'/', '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
The first 2 lines are commented out, this is what was here. As I trust and know how my server is setup (cause I did it myself) I don't feel any need for this check system.
One other thing to be aware of on a Windows system is that you will have to add the suggested Server_URI parse at the start of this file too.
if (isset($_SERVER['HTTP_X_REWRITE_URL'])){
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
I hope this helps someone... It's taken me all day to resolve with no online support.

Redirect ALL requests under a domain to static page [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
I am trying to redirect ALL requests for mydomain.com whether they are something like:
http://www.mydomain.com
http://mydomain.com
http://mydomain.com/photos
http://mydomain.com/index.php?id=672
to be redirected to
http://mydomain.com/index.html
As long as it has mydomain.com in it, they should see this page - its a we'll be back soon message.
Should I do it in .htaccess or conf? How?
I actually ended up finding the answer on ServerFault:
https://serverfault.com/questions/32513/url-redirect-to-another-page-on-the-same-site
"This example will 302 redirect all URLs to "/underconstruction.html":
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^ /underconstruction.html [R=302]
(which translates as "If URI is not /underconstruction.html, redirect to /underconstruction.html")" - Tommeh