.htaccess redirect pagination - .htaccess

At present my url structure of page is like this
Mysite.com/page-2
mysite.com/categoryname/page-2
I want to change it to
mysite.com/page/2/
mysite.com/category/categoryname/page/2/
Note that, I have multiple page, i.e. let's say a category have 100 page so I need to redirect all the earlier page number to the new url structure. Writing code of every url will be too tedious. I am not sure but using $ in the code can help.
Please let me know how can it be done via .htacess.
Thanks in advance.

Your URL structure is already with the desired one you have as I can see.
/category/telecom-news/page/2

Related

Keep people from opening pdf directly on my webiste

I am not sure if this is possible, but I figure I would ask.
I have hundred of PDF's stored on my website, and they are all getting indexed directly by Google, so people are doing a search and the engine is taking them directly to the PDF. The issue here is that the PDF's are related to language learning and have audios that go with them. If a visitor goes directly to the PDF, then they never see the audios.
I have another page I have designed which opens up the PDF in an Iframe, and shows the audios right next to them so the users can use it.
So my question is, is it possible to redirect a user who opens:
www.mywebsite.com/something.pdf
And have it redirect them to:
www.mywebsite.com/page-with-audios/
The key here is that the pdf should still open in the IFrame on my domain.
Thanks in advance for any assistance.
If you use routing, you could make a route which has the PDF name as parameter. The route could look something like this:
/{PDF_NAME}.pdf
This could be used to match all PDF's, like example.com/foo.pdf, example.com/bar-baz.pdf. Since you then have the name of the PDF they would like to view, you can redirect them to the /page-with-audio-files with some extra data like the name of the PDF. Then you can handle opening the iFrame.
EDIT
since I now see your question was directed at .htaccess, I think the following might work too.
add this rewrite to your .htaccess:
RewriteEngine On
RewriteRule ^([a-zA-Z\-]+.pdf)$ /page-with-audio/$1 [L, R=301]
This will make the $1 variable somepdf.pdf if your request url is http://example.com/somepdf.pdf.
Then it redirects the user to http://example.com/page-with-audio/somepdf.pdf so you know which pdf was requested.

RewriteRule - redirect multi variable URL to multi variable URL

Our old website has a search URL structure like this:
example.com/Country/United States/Region/California/Area/Southern California/City/San Diego/Suburb/South Park/Type/House/Bedrooms/4/Bathrooms/3/
This is currently rewritten to point to the physical page:
/search/index.aspx
The parameters in the URL can be mixed up in different orders, and the URL can include one or more parameters.
We want to 301 redirect these old URLs to a new structure that is ordered in a logical way and more concise:
example.com/united-states/california/southern-california/san-diego/south-park/?type=house&bedrooms=4&bathrooms=3
example.com/united-states/california/?type=house&bedrooms=4&bathrooms=3
Is there a way with URL rewriting to interrogate the old URL, work out what parameters are existing and then write out the new URL structure?
Even if we can limit it to just the Country, Region, Area, City and Suburb, that may be good enough to at least return some results even if it's not perfect.
Also, spaces should be turned into hyphens and all text made lowercase.
I already have the RewriteRule to turn the new URL structure into a URL to point to a physical page. It's just transforming the old URL in to the new URL I need help with. I've googled endlessly and it's just beyond me!
Can anyone help? Thanks.
Since you already have the old search page with rewriting rules set up for it and which is capable of parsing all parameters you need, the easiest and most appropriate solution I see here is to issue a redirect you require from this old search page's code. Just put the code that composes new URL with all parameters needed and redirects from this page - this should be a lot easier than trying to parse all these parameters in .htaccess and combine them into the new format.

How do I redirect a page to another page in such a way that they both look the same?

I need to redirect https://example.com/projects/issues/(some_text_here) to http://example.com/i/(same_text_here) in such a way that it /i/(same_text_here) shows the same page that /projects/issues/(some_text_here) shows. Is this possible? How would I do this. Please post the code I would use (along with helpful comments explaining why something goes where it does). Thanks!
EDIT: I believe I would have to use the htaccess file?
EDIT 2: By (some_text_here) I mean so random text, like a wildcard. It could be /projects/issues/34... or /projects/issues/hello. In this case first example should redirect to /i/34, and the second example should redirect to /i/hello
Try this out in your .htaccess:
Redirect /projects/issues/ http://example.com/i/

Existing movable type plugin that does URL shortening and redirection?

We send out a newsletter that has URLs in it. Rather than having foreign URLs directly, they all come to our website and then redirect to the outside world.
Right now the redirects are all done with HTML files. My goal is to have them all done with redirects in the .htaccess file. So I want to have the person who is entering all of this data enter it all through the movable type GUI.
My questions:
Is there is plug-in for movable type that already does this?
If not, is there a good template for creating a movable type that allows one to records in the MySQL database?
Thanks.
This could be done in the standard Entry interface in MT. Just dedicate a blog for these redirects. You could make the EntryTitle the redirect and have the EntryBody be the full URL (or use Custom Fields). Then just create an .htaccess template that loops through all the entries.
<mt:Entries lastn="0">
Redirect /<mt:EntryTitle dirify="-"> <mt:EntryBody>
</mt:Entries>
The way I would do this is to create a custom field for the outside URL.
Then I would populate the .htaccess file with something like:
Redirect /
In the above coding, I'm looping through the latest 999 entries and I'm checking if the custom field with the tag 'EntryDataMyCustomField' is filled out.
If it is filled out, then I redirect / to the URL from that custom template.
This is like redirecting say:
/234 to whatever URL you may think of, like say:
http://en.wikipedia.org/wiki/Main_Page

help with htaccess query strings appending constantly

I have an htaccess rule that goes:
RewriteRule ^Commercial-Units/For-Sale/(([a-zA-Z]+)*/([0-9]+)*/([a-zA-Z]+)*/([0-9]+)*/([a-zA-Z]+)*/([0-9]+)*)*$ pages/index.php?f=quicksearch&cust_wants=1&want_type=2&at=$3&start=$5&limit=$7 [R=302,L]
This is specifically designed for when a page requires paging records.
I have been trying to find solutions over everywhere in Google and Stackoverflow.com..
The problem is that everytime someone clicks on, say page 2, the address bar keeps on adding my query strings like so:
http://mysite.com/Commerial-Units/For-Sale/page/2/at/10/limit/7/page/2/at/10/limit/7
notice that the url above containes multiple key-value combinations duplicated and this goes on and on everytime someone clicks on the next page...
Hope someone can point me to the right solution to this...
Thank you very much!
Thats not a problem with your rewrite but with your site code the links are adding /page/2/at/10/limit/7 to the current url you need to remove the previous params using something like ../../../../../../page/2/at/10/limit/7
And if that is for SEO please use parameters for pagination, only use SEO friendly urls for categories and items, no need to index every single pagination option, as that will be duplicated content.

Resources