.htaccess: Replace part of url [closed] - .htaccess

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 got some duplicate content and want to redirect to the right url (remove a part of the url and redirect)
Examples:
http://www.domain.com/en/url/1-url
http://www.domain.com/es/url/1-url
http://www.domain.com/fr/url/1-url
....
The individually should redirected to:
http://www.domain.com/en/url
http://www.domain.com/es/url
http://www.domain.com/fr/url
....
Because I have to do this for a lot of urls, I can't redirect them each manually and need a rule which detects if the url contains "/1-url" and if yes remove this part from the url - but only this part.
Would be great if a mod-rewrite hero can help me with this. I'm searching for solution over .htaccess via a rewrite rule.

Check this:
RewriteRule (\w{2})/([^/]+)/\d+-[^/]+$ /$1/$2 [R=301,L]
RewriteRule ([^/]+)/\d+-[^/]+$ /$1 [R=301,L]

If you use a imported file to each 1-url page only add redirect method to imported file.
For example your every 1-url page have header.php, add redirect function to header.php

Related

Redirect links with specific parent and preserving structure [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 1 year ago.
Improve this question
I want to redirect all the links that have specific parent to a subdomain, while preserving url structure.
Example:
domanin.com/topic1/subtopic1/subtopic2/
redirect to
sub.domain.com/topic1/subtopic1/subtopic2/
Thank you.
To redirect all requested URLs that start /topic1/ (the "specific parent") from example.com to sub.example.com then you can do something like the following using mod_rewrite at the top of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)
RewriteRule ^topic1(/|$) https://sub.%1%{REQUEST_URI} [R=302,L]
This will 302 (temporary) redirect URLs of the form:
example.com/topic to sub.example.com/topic (which will also redirect to sub.example.com/topic/ by mod_dir if topic is a physical directory)
example.com/topic/ to sub.example.com/topic/
example.com/topic/subtopic1/subtopic2/ to sub.example.com/topic/subtopic1/subtopic2/

Virtual Folders [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
I'm trying to utilise mod_rewrite allowing me to use domain.com/d4k1d to give the same effect as domain.com/link.php?link=d4k1d
At the moment I have this in my .htaccess although this seems to give me 404 errors.
RewriteEngine on
RewriteRule /(abcdefghijklmnopqrstuvwxyz[0-9]+)/ link.php?link=$1
I'm not too familiar with mod_rewrite etc. so I don't know where to go with this :S.
You need to include all of the letters inside of the character class (which can also be simplified). Your current rule only allows for a letter followed by one or more numbers:
RewriteEngine on
RewriteRule /([a-z0-9]+)/ link.php?link=$1
You need to remove the leading slash because it's stripped from the URI by apache before being used in rules that are in an htaccess file.
RewriteEngine on
RewriteRule ^([a-z0-9]+)/?$ /link.php?link=$1 [L]

force php file to subdomain [closed]

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 8 years ago.
Improve this question
I have a file called video.php on my domain but want it on my subdomain.
now its like www.domain.com/video.php?id=parameter&fewotherparamer=1233
and I want to change it to
video.domain.com/video.php?id=parameter&fewotherparamer=1233
how would this be possible? I already tried to find out using google and the searchfunction here, but didn't find the point.
Thanks
add these directives to .htaccess file in domain.com root directory (or virtual host config) and make sure you enabled mod_rewrite module
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteRule ^video.php$ http://video.domain.com/video.php [R=301,NC,L ]

How To Use 301 Redirect In htaccess To Stop 404 Errors? [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 two domains with same name but different TLD like .com and .net.
i'm using blog on ".com" domain and forum on ".net" domains like
Sites 1: "http://www.mywebsite.com/" (blog)
Site 2: "http://www.mywebsite.net/forum" (forum)
I'm facing problem with Google webmaster tool, webmaster tool trying to crawle my .com domain as forum hosted like "www.mydomain.com/forum" however forum not exist on .com domain. its exist on .net domain. so its generate 404 errors.
Please, let me know some code to to redirect ".com/forum/ {Plus Queries} /" to exact ".net/forum/{ Destination }" i believe its help to mark remove 404 errors or help to prevent more errors.
however, today I've set my robots.txt to disable Google crawling on ".com/forum"
In the htaccess file in your document root for the .com domain, add:
Redirect 301 /forum http://www.mywebsite.net/forum
If both domains share the same document root, thus sharing the same htaccess file, then you'll need to do an additional check for the host by using mod_rewrite instead of mod_alias:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.com$ [NC]
RewriteRule ^/?forum/(.*)$ http://www.mywebsite.net/forum/$1 [L,R=301]

How to remove directory from URL [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 11 years ago.
Improve this question
I would like to remove directory from URL. I have a page in mydomain.com/dir/ and all links works under mydomain.com/dir/link1.html, mydomain.com/dir/link2.html etc.
I would like to create single URL which will be mydomain.com/new_link and will trace to mydomain.com/dir/index.php?page=13. I would like it to do only once, for one link, not a regular expression. .htaccess file is located in dir directory with the following content:
RewriteRule ^new_link$ index.php?page=13 [L]
But this causes that the dir is still visible.
I do not entirely understand your question. From what I have understood,
if you want to remove dir from your URL, have your .htaccess in parent directory of dir. I think its the DocumentRoot in your case.
And add this RewriteRule:
RewriteRule ^new_link$ dir/index.php?page=13 [QSA,L]

Resources