i have a url like this http://example.com/blog/photos/photos/gallery/image/1.
And i need to remove the second photos folder. How do i remove the part using mod_rewrite and .htaccess?
For your interest /blog is my document root.
Thanks a lot for any suggestions, Steve
EDIT
You should know that the URLs being generated by Wordpress 3.0 und NextgenGallery.
http://example.com/blog is my document root. That means i have installed Wordpress into the folder blog.
The first slug after blog is the page i have my gallery associated with.
The second slug is the name of the album and could be renamed to everything you want. It is just a placeholder for my galleries. gallery is the name of the gallery.
Assuming you want to do a redirect:
RewriteRule ^/blog/photos/photos/(.*)$ /blog/photos/$1 [R]
Related
I am trying to change the permalink structure of my Wordpress site and setting up proper redirects. Here is what I am trying to achieve:
Old permalink structure:
/category/post-name
New permalink structure:
/postname
Redirecting would be fairly simply done by:
Source:
/category/(.*)
Destination:
/$1
However, the base URL without the post-name must not be rewritten. So if someone access /category directly (without specifying a post-name) it should not redirect, because /category is a valid page. It should only redirect if something is following /category.
Example:
https://somesite.com/category -> Don't redirect
https://somesite.com/category/post-123 -> redirect URL to https://somesite.com/post-123
Any ideas how I can do this? Note: I am using the Yoast Plugin and its RegEx redirect option.
I am not a coder, so sorry for my gibberish. I hope I am making some sense.
Thank you! :)
Use .+ to match at least one character:
/category/(.+)
My post URL structure is http://example.com/slug and the category URL is http://example.com/category/category-name.
Currently, my custom structure is /%postname%/ and the category base is blank.
I would like to change the category URL to http://example.com/category-name. How do I go about this?
I tried with htaccess but got 404 error:
RewriteRule ^category/(.+)$ http://www.yourwebsite.com/$1 [R=301,L]
You're receiving a 404 because you're sending users from http://example.com/category/category-name to http://example.com/category-name, which doesn't actually exist as a page, yet.
The RewriteRule is a redirect, rather than framing the URL.
From the sounds of things, you actually have a category base set within Wordpress (hence the "category/" before the category-name), which can be removed by going to "Settings" -> "Permalinks" -> "Category base" in the Wordpress panel.
In the event you're also using YoastSEO, you may wish to reference this documentation from Yoast.
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
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.
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)