I have created a .htaccess file for my site in order to simplify its URLs. The entire .htaccess reads as follows (and works as desired)(Improvements thanks to anubhava) :
Options -MultiViews
RewriteEngine on
RewriteRule ^home/?$ index.php [NC,L]
RewriteRule ^news/?$ news.php [NC,L]
RewriteRule ^news/([0-9a-zA-Z]+)/?$ news.php?id=$1 [NC,L,QSA]
The only issue I'm facing now is that the facebook share link (that appears on each news article page eg. news/3) gives an error: specifically, clicking on it generates a Server Error 500 page instead of the facebook share window.
The details of the Server Error 500 read:
The website encountered an error while retrieving https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Flocalhost%2Fexperiment%2Fprefinalkoh%2Fnews%3Fid%3D6. It may be down for maintenance or configured incorrectly.
Do note: am not able to get Apache error log details for this for some reason even though I set display_errors = On display_startup_errors = On and error_reporting = E_ALL
The exact fb sharelink that appears on the news.php is as follows:
<a href="#"
onclick="
window.open(
'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
'facebook-share-dialog',
'width=626,height=436');
return false;">
Share on Facebook
</a>
What can I do to fix this issue - given that I need to have those statements in the .htaccess, while also requiring the fb share link working. My understanding is the facebook link is not 'getting' the cleaned-up link of the current page to be shared & probably a condition needs to be put into the .htaccess?
Would appreciate any help on how to address this.
RESOLUTION: This issue was resolved when as suggested by Mike Rockett in comments, I shifted my project from localhost to liveserver.
Related
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]
I'm trying to make a file only accessible when you're on a specific page.
Like download.php, the user can click a link to the file and the download starts without problems.
But if you go to the link in the browser directly it should not work.
Could I use .htaccess for this? or how would I do this?
This is possible with .htaccess by checking for the ${HTTP_REFERER}, which is the previous url you were on.
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://www.example.com/download.php
RewriteRule myFile.zip - [R=403,L]
This checks if the previous page was download.php, otherwise it rewrites the request for myFile.zip to a 403 error page.
Note that it is possible to forge a referer by intercepting / creating your own request. This does not provide 100% security.
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.
Ive a site with links in the page which lives in root are of the format:
/documents/mimecast-email_continuity_whitepaper.pdf
(correct physical path)
but by the time it comes out in the browser results in the following error (naming the correct path)
"This webpage has a redirect loop
The webpage at name-of-website/documents/Comtec-Relocations-Case-Study-v4.pdf has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Here are some suggestions:
Reload this webpage later.
Learn more about this problem.
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects."
The rule Ive put in is
-.htaccess (in file)---------- (in my root directory - where all the web pages live)
Options +FollowSymLinks
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(pdf)$
RewriteRule (.*) http://dev.comtec.com/$1 [R=301,L]
(edited as my first question wasnt very clear apologies)
Appreciate any thoughts
K
I have an old website - written in asp. The contact form uses a querystring to decide which form the visitor sees.
If a vistor wishes to just contact me, they may do so by clicking the link to:
http://example.com/contact.asp
If they wish to submit a fault - they do so by clicking the following link
http://example.com/contact.asp?problem=true&.......
Additional parameters are also passed after problem nb: ?problem=true&Customer... - however, I only need to know if problem=true
In the new site I have two pages: contact.html, and help.html
When a visitor goes to contact.asp they are redirected to contact.html - thanks to the following redirect rule:
RewriteRule ^contact\.asp$ http://example.com/contact-us.html [R=301,L]
However, I am having MASSIVE problems trying to get
http://example.com/contact.asp?problem=true to redirect to help.html
I've found tons of examples - but none of them work.. the page always redirects to contact.html
I have even commented out the above rewrite rule to see if my problem=true rule was being over-ridden.... This returned a 404. My problem=true rule just doesn't work.
I've been following examples such as: http://www.simonwhatley.co.uk/apache-htaccess-query-string-redirects
So to recap, I'd like to redirect contact.asp?problem=true to help.html, and contact.asp to contact.html
Many thanks in advance,
Rob
Not sure what you have tried as far as matching the query string, but the following should work.
RewriteCond %{QUERY_STRING} ^problem=true
RewriteRule ^contact\.asp$ http://primarysite.net/help.html [R=301,L]
RewriteRule ^contact\.asp$ http://primarysite.net/contact-us.html [R=301,L]
Hope that helps.