htaccess replace one parameter with other in url - regex

I have installed WordPress in in subdirectory.
My url is domain/blog/post-title
now I want domain/pages/post-title
only want change blog with pages, how i can do it in htaccess so all my old url's can 301 redirect on new url?
Thanks

Related

Mask forwarded blogger urls to own domain urls

Following Rounin's answer carefully written (thanks a lot) on how to redirect any blogspot urls with any extension to the mydomain.com corresponding URL, now the question is how can I mask the URL?
I mean, once the blogspot URL redirects to the mydomain.com, I want to continue to display the original blogspot URL instead of the mydomain.com.
You can use the following JavaScript snippet for that -
<script>
site = "http://example.com"; // The site which you want to mask, don't add ending slash
iFrame = document.createElement("iframe"); // Creates a iframe via JavaScript
iFrame.setAttribute("src", site + location.pathname); // Set the source of iFrame
iFrame.setAttribute("class", "maskingFrame"); // Add class to iFrame
document.body.appendChild(iFrame); // Append iframe to body of page
</script>
And the bare minimal CSS would be -
body {
overflow:hidden;
}
.maskingFrame, body {
width:100%;
height:100%;
border: none;
}
You can check a demo here (This is the homepage) and here (This is an internal URL from other site which doesn't exist on the original blogspot URL)
In privous answer you redirected page from blogspot to your domain. This causes the url to be changed. But if you want to show contents from another url without changing url it could be done through using .htaccess file.
the code in htaccess file should be like this:
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://DomainB.com/$1 [P]
Here you could find more details and info about .htaccess file.
I don't know if it is possible for you to place that file in your blog or not. If you have not access to place this file into your blog you can place it on your domain host, and redirect from your domain to your blogspot page but if ask me I recommend you redirect and encourage people to your own website rather than keeping them using weblog address. You'll not need weblog if you have your own website.

htaccess 301 redirect page url to another page

Can I use htaccess to get values from the input url and change it in the redirection example:
www.example.com/cars-minneapolis-mn/
redirect to
www.example.com/cool-suv-auto-in-minneapolis-mn/
you can try with many ways here is one:
RedirectMatch "^/cars-minneapolis-mn\/?$" "http://example.com/cool-suv-auto-in-minneapolis-mn/"
this will redirect your existing url to new url

301 redirect domain and all its pages

We have 2 sites on the same niche and basically with the same content, we are going to just close one of them and 301 everything to the one we will be keeping, content is basically the same the only difference is basically the url structure of some pages:
In the one to be 301:
www.domaintobeclosed.com/browse-{keyword}-url string.html
In the one to be redirected to:
www.domaintokeep.com/browse-url string.html
So here the only difference is that in the domain we are keeping the url structure doesnt have the keyword.
The other difference is that in single page url structure:
In the one to be 301:
www.domaintobeclosed.com/title.html
in the one to be redirected to:
www.domaintokeep.com/keyword/title.html
So the difference is that the domain to keep has a keyword before the actual title
Any help on this will be greatly appreciated.
Thanks in advance.
So something like:
RedirectMatch 301 ^/(browse)-keyword-(.*)$ http://www.domaintokeep.com/$1-$2
RedirectMatch 301 ^/([^/])\.html$ http://www.domaintokeep.com/keyword/$1.html

301 redirect from old to new URL without querystring and?

I'm trying to redirect from my old URL structure to a new one where in my case some parameters are added.
The old structure looked like www.url.com/detail/111.html which is rewritten from www.url.com?action=detail&id=111
Now the structure changed for SEO reasons, new the URL for the site mentioned above is something like www.url.com/detail/111/cat/sub.html.
Now i want to redirect from
www.url.com/detail/111.html to
www.url.com/detail/111/cat/xyz.html
or from
www.url.com/detail/112.hmtl to
www.url.com/detail/112/cat/abc.html
The last part in the new URLs is variable!
If im doing it with:
Redirect 301 /detail/112.html http://www.url.com/detail/112.cat/abc.html
the querystring ist added to the new url. The browser shows: http://www.url.com/detail/112.cat/abc.html?action=detail&id=112
When I'm adding a ? to the new URL the ? is also shown in the browser.
QSD doesn't work because Apache 2.2 is running.
Has anyone an idea what to do to solve the problem?
You can put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^detail/112\.html$ http://www.url.com/detail/112.cat/abc.htm? [L,NC,R]
Take note of ? at the end of target URL that is used to strip off any existing query string.

How to redirect a http request with apache / django

I've made a simple site in Django. The urls I use are http::/www.example.com/nl/ and http://www.example.com/fr/.
My Django urls.py has the following line:
(r'^(?Pnl|fr)/', 'example.views.index'),
In example.views.index I check the language parameter. If it's 'nl' I show a template. If it's 'fr', I show a different template.
This worked great. Now the customer made two different urls:
http://www.dutch.com/ and http://www.french.com/
And finally I'll ask the question:
Is there a way for me to use the new urls without changing my django code? I assume I can tell apache to present the http://www.example.com/nl/ page when the user goes to http://www.dutch.com/. But how do I do this? And will django still be able to get the 'language' parameter from the url?
Thanks in advance for any answers.
If you can use .htaccess files on http://www.dutch.com that you can use apache's redirect directive like so
redirectMatch 301 ^(.*)$ http://www.example.com/nl/
This will redirect all requests sent to dutch.com to example.com/nl
You could also use
redirect 301 /index.html http://www.example.com/nl/
This will redirect only "index.html" on dutch.com to example.com/nl/ (note that the first parameter is a path and can't be an URL - no http://www)