redirect in htaccess with partly remove of a weblink - .htaccess

I am using simple mod-rewrite rule:
Redirect 301 /feeds/ https://some-interesting-website.../feed/index.php
It doesn't work because if I have some link:
/feeds/some-difficulf-link/many-files-and-folders.php than result is:
https://some-interesting-website.../feed/index.phpsome-difficult-link/many-files-and-folders.php
How could I remove a rest of a link after index.php?

It was really hard job. I was need to pay a lot of time and efforts in it to find a solution.
Looks like mod rewrite logic is not very clear. However this code worked perfect for me: Redirect 301 /feeds https://some-interesting-website.../feed/index.php?

Related

how to rewrite SEO friendly url in htaccess

How to create an SEO friendly URL like example.com/pages/my-first-page/followers here I want how to create a structure in if(isset($_GET['followers'])){...} and htaccess file.
My link working fine till example.com/pages/my-first-page/ but now I want to add followers section.
I hope i explain well what I expecting. Thanks for your help
Rule you've suggested is this:
RewriteRule ^pages/([\w-]+)/followers/?$ page.php?pages=$1&followers=1 [QSA,NC,L]
This is pretty good rule and there is no reason why it should not work. Make sure this rule is placed before page rule which is your first rule in .htaccess

How to redirect in htaccess with a wildcard

This is really bugging me, for something that should be real simple.
Trying to 301 redirect a URL (via htaccess) - in the following manner:
https://www.example.com/forums/sub-forum/index.php
needs to be redirected to:
https://www.example.com/forums/sub-forum/
Basically want to get rid of the index.php (note: the sub-forum is a wildcard, as it can be anything, e.g. football-forum or tennis-forum etc...)
So far I've managed to work out that I need to do something along these lines:
RedirectMatch 301 ^/forums/.*/index.php /forums/<wildcard>
However, I'm not sure what to put in instead of <wildcard> part. I've tried putting .*, but that doesn't work
Any ideas on how to achieve this? Your help would be much appreciated.
Many thanks.

htaccess redirecting from rewritten dynamic urls to new dynamic urls

i am experiencing a very unique problem and i hope someone can help!
so we have recently created a new ecommerce website and we made it live and everything was working great but when we to implement our 301's from our old pages we were getting some wierd things
so the code below actually works
Redirect 301 /directory/ http://mysite.com/index.php?cat=1
this code does not
Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2
the output when i try to do this redirection is "Invalid parameters specified!" on a blank webpage and in the address bar it has this
http://mysite.com/index.php?cat=1/sub_directory/
we were thinking that maybe the problem is because our old pages were dynamic but mod_rewrite was used to create more readable urls and we have also deleted all our old files because they were interfering with our new pages rendering
any help would be greatly appreciated!
thanks
That is strange, as redirect should only match the specific url listed, where as it looks like its behaving like rewriterule and partially matching the subdirectory url against the first rule..
try putting the more specific rule above the less specific, like so:
Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2
Redirect 301 /directory/ http://mysite.com/index.php?cat=1
That way the more specific rule will be hit first, and the /directory/ only rule will only match if more specific matches above fail
alternatively, you could try RewriteRules:
RewriteRule ^directory/$ http://mysite.com/index.php?cat=1 [R=301,NC,L]
RewriteRule ^directory/sub_directory/$ http://mysite.com/index.php?cat=2 [R=301,NC,L]
the ^ and $ anchors should prevent any unwanted partial matching

htaccess 301 mod rewrite matching url pattern

This one's beyond my ability I'm afraid and after much research and breaking things I've come for help. I have a site with a URL in the format of:
example.com/7865/travel-photo/my-amazing-photo
My client has now decided he'd like to add an 's' onto photos so the URL has become:
example.com/7865/travel-photos/my-amazing-photo
All great and that alone wouldn't have been a problem only for the fact that the number '7865' changes for each URL just like the 'my-amazing-photo' does. The basic structure of the new URL needs to be:
example.com/'number variable'/travel-photos/'article name variable'
So my question how does write a beautiful htaccess mod rewrite rule for that?
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)/travel-photos/(.*) $1/travel-photo/$2

using mod_rewrite to create SEO friendly URLS

I've been searching google for this but can't find the solution to my exact needs. Basically I've already got my URL's named how I like them i.e. "http://mysite.com/blog/page1.php"
What I'm trying to achieve (if it's possible!) is to use rewrite to alter the existing URLS to: "http://mysite.com/blog/page1"
The problem I've come across is I've found examples that will do this if the user enters "http://mysite.com/blog/page1" into the broweser which is great, however I need it to work for the existing links in google as not to loose traffic, so incoming URLS "http://mysite.com/blog/page1.php" are directed to "http://mysite.com/blog/page1".
The 1st example (Canonical URLs) at the following is pretty much what you want:
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#url
This should do the trick, rewriting requests without .php to have it, invisible to the user.
RewriteEngine On
RewriteRule ^/blog/([^.]+)$ /blog/$1.php
You will need to write a rewrite rule for mapping your old url's to your new url as a permanent redirect. This will let the search engine know that the new, seo friendly url's are the ones to be used.
RewriteRule blog/page1.php blog/page1 [R=301,L]

Resources