How to perform htaccess rewrite - .htaccess

Here is the summary of my problem.
I have created a Facebook like button. It works correctly most of the time, however not when following the link from somebody's actual "like" post. It seems that Facebook is adding some more info to the URL. For instance, I have
www.example.com/blog.php/6
but Facebook adds
www.example.com/blog.php/6?fb_action_ids=10201090685057512&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582
When a user follows this link they get a Mysql syntax error. If they follow the first link there is no problem. I thought I could just strip off all that extra text from the URL.
I created a .htaccess file and placed it in my root directory on GoDaddy.
I Tried several different rewrites.
Nothing has worked. This is the latest thought I tried:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?fb_action_ids=
RewriteRule ^(.*)$ $1?%1 [R=301]
Do I need to change my .htaccess file or is there another way to solve this problem?
Thanks for the help.

Related

Block specific url with ? with htacess

Firstly, I can't get the correct code looking at other post here, not working for me hahahaha.
I would like to block this specific url: /2017/06/wonder-womannuestra-princesa-feminista.html?m=1 (Related to an old blogger url)
Don't know why but different ips, without referrer and user agent, are spamming (not a real visit cause after a redirection to the new one on WordPress they visit all the links in the url) my site always entering by this url and I would like to block ONLY this one.
I've tried to redirect this one with Redirection plugin but I have a redirection to all "?m=(*)" and this one is the one working, not the one related to the specific url.
I just used : RewriteCond %{REQUEST_URI} ^/2017/06/wonder-womannuestra-princesa-feminista.html?m=1 but it doesn't work.
Could you help, I think the problem is that I'm not witting the correct code due to the "?" character. Many thanks.
With your shown samples, attempts considering that you need to block url(mentioned in comments/question), if this is the case then try following. This rule will forbid this specific url from being accessed.
Please these rules at top of your .htaccess file. Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/2017/06/wonder-womannuestra-princesa-feminista\.html\?m=1 [NC]
RewriteRule ^ - [F,L]

Mod Rewrite rewrite URL weird behavior, keeps adding query string to displayed URL

I'm a beginner.
What I want
the request URL .../activity/1415/abcdefgh/ to be rewritten to .../activity/gallery.php?k=abcdefgh
but still display the URL to the visitor as .../activity/1415/abcdefgh/.
But when I try, the URL .../activity/1415/abcdefgh/ turned to .../activity/1415/abcdefgh/?k=abcdefgh.
The page displays fine, but I want to hide the query.
Basically what happened
Link says: http://localhost/activity/1516/iolfpqwx
Clicked link
Address bar says: http://localhost/activity/1516/iolfpqwx/?key=iolfpqwx, which I don't want.
My entire .htaccess in the activity/ directory:
RewriteEngine On
RewriteRule ^(\d{4})/(\w{8,})(?:/([\w\s]+)?)?$ gallery.php?key=$2 [L,QSA,NC]
My Specs:
XAMPP on Windows with Apache
What I know
I have not setup any redirect rules on my testing server, so I don't believe I have any [R] flags.
I have a similar .htaccess in an adjacent directory with the code RewriteRule ^settings/([^/]+)/*$ index.php?p=settings&s=$1 [L,QSA,NC] and it didn't show me query strings.
I've Googled my issue, but cannot find a solution. Please help.

Broken links in a Drupal subdomain

Currently I have a site, https://mysite.com/ a working Drupal7 site. I want to have something like this, https://mysite.com/dev in order for me to test the things first on this location before finally uploading it to the main site. What I did was copy the entire folder where all the files located and pasted it inside /dev. I made a duplicate of the DB being used by the main site and edited the file settings.php under sites/default/, edited the base url from https://www.mysite.com/ to https://www.mysite.com/dev. But when I tried navigating the pages using the links(menu, admin) it gives me Page not found response. In addition, I did uncomment this line RewriteBase / on my .htaccess file. I can also log in, but after logging in the links point to the main site like this, https://mysite.com/link1, https://mysite.com/link2 and so on. What did I miss? Can someone please help? Thanks!
I think I finally got it working. I did mention I edited a single line on my .htaccess file which is the RewriteBase / and I did, I promise. I changed it to RewriteBase /dev but when I tested the site, the links still go to the main site as I have mentioned above. What I did was research more on editing .htaccess and somewhere down the road I got here. I lack a few lines of codes which will solve my dilemma, somewhere between RewriteCond and RewriteBase lines. I need to add these lines, RewriteCond %{REQUEST_URI} ^/dev
RewriteRule ^ dev/index.php [L]. After adding these two lines, I tested the site again and it worked like magic. That's it. Thank you guys.

Redirect any url containing /foo/

I'm trying to redirect a series of around 400 urls using .htaccess/Apache containing a given /directory/ anywhere in the url to a specific location.
The problem here is that my site is receiving requests for an old site hosted on our servers ip. I've tried manually redirecting the urls but the volume is simply too great.
I've searched but can only find examples for redirecting query strings or files
Thanks in advance.
Ok, if all links have the same directory in there... example store/funstuff/blahblah.php
and funstuff is the directory you are looking for then you could modify your .htaccess file something linke this
Options +FollowSymlinks
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_URI} funstuff
RewriteRule . http://www.gohere.com/
Then if you needed to pass more of the URL info you could do the last line like this:
RewriteRule ^(.*)$ http://www.gohere.com/1$
That should get you started... you may need to tweak it slightly.
What language are you processing the redirects in?
You probably need to use a regular expression that searches for the given /directory/.
If I understand your question correctly and that you are using Apache; RedirectMatch should do what you want.
It accepts a regexp for matching and can then redirect to the place you choose.

.htaccess Rewrite Based on Existence of Path in URL

Here's the scenario, I have a website that used to be a static HTML site and WordPress blog using a subdomain (http://blog.domain.com).
I recently combined everything into a single WordPress installation. To maintain old links I had to rewrite requests like "http://blog.domain.com/index.php/2010/10/16/post-name" to "http://domain.com/index.php/2010/10/16/post-name". My problem is that when trying to visit just "http://blog.domain.com", I get redirected to "http://domain.com" when I want it to go to "http://domain.com/index.php/blog".
So, if a user requests "http://blog.domain.com" (by itself, with or without slash), I want it to go to "http://domain.com/index.php/blog". If they request an old URL of "http://blog.domain.com/some-link-to-a-post", I want it to redirect to "http://domain.com/some-link-to-a-post". In other words, if it's a URL to an actual post, I just want to strip the "blog" subdomain. If it's the old link to the main blog page, I want to remove the "blog" subdomain and append "/index.php/blog"
http://blog.domain.com/ -> http://domain.com/index.php/blog
http://blog.domain.com/index.php/2010/10/16/post-title -> http://domain.com/index.php/2010/10/16/post-title
Hopefully that's clear. I'm not an htaccess expert, so hopefully someone can help me out here. Thanks in advance!
Using the [L] command at the end of a rewrite will tell htaccess that this is the last rule it should match. If you put a rule to match your first condition at the top and the other rewrite rule you said you had already created after it, you should get your expected result.
Try this:
RewriteRule ^blog.domain.com(/?)$ domain.com/index.php/blog [L]
# Your other rewrite here #
I couldn't get that solution to work. However, I used the following:
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/index.php/blog/$1 [R=301,L]
That ends up in a URL like http://domain.com/index.php/blog/index.php/2010/06/04/post-title, but Wordpress is smart enough to fix it.

Resources