.htaccess: Strange url have slash / at the end of urls, and .php - .htaccess

I have check google webmaster tools and see lot of URLs that has been crawled, they look like:
mydomain.com/somefile.php/index.php
or
mydomain.com/somefile.php/somefilesss.php?aaa=bbb&ddd=ddd
or
mydomain.com/somefile.php/someffiiii.php?iii=uuu/somefilesss.php?aaa=bbb&ddd=ddd
This is really strange.
Look like someone add the slash to URL when enter address bar, then google following them.
Currently I get fix by remove slash at the end of URLs by this .htaccess:
If it come like .php/, it will become .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R=301]
But the issue is other URL still remain in google index.
I need solution to redirect the URLs which have trailing slash after php then have other file path to come back to original.
I need help to redirect eg:
mydomain.com/somefile.php/somefilesss.php?aaa=bbb&ddd=ddd
to
mydomain.com/somefile.php
Thanks for any advices.

There are 2 possible explanations to this:
Fantastic: somethere in the web, this links exist and google follows them;
Realistic: there is a bug somethere in your php engine, which produces such links and google follows them.
So IMHO you should not care about creating a rewrite rule, but check php engine for this bug.
As time passes google will "forget" previously collected urls.

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]

redirect rule for multiple pages

I have page not found erros in webmaster because the page/2/0 part of a url is due to smart paging module clean url feature (Drupal) now i uninstalled the smart paging module but these page not found errors are still there.
www.mysite.com/a/b/c/page/2/0,
www.mysite.com/a/d/e/page/3/0,
www.mysite.com/a/f/g/page/4/0,
www.mysite.com/a/h/i/page/5/0
and so on.
I want to redirect
www.mysite.com/a/b/c/page/2/0 to www.mysite.com/a/b/c
www.mysite.com/a/d/e/page/3/0, to www.mysite.com/a/d/e
www.mysite.com/a/f/g/page/4/0, to www.mysite.com/a/f/g
www.mysite.com/a/h/i/page/5/0 to www.mysite.com/a/h/i
with one redirect rule. How to do this
in short i want to remove the page/x/0 part from the url and redirect it to the remaining part of that url.
You want something like this:
RewriteEngine On
RewriteRule ^/?([^/]+)/([^/]+)/([^/]+)/page/[0-9]+/0$ /$1/$2/$3 [L,R=301]
The literals here are after the first 3 path nodes: /anything/anything/anything/, then it must be followed by a page, then some numbers, then a zero. You can make it even more general, say after the "page", by changing the pattern to:
RewriteEngine On
RewriteRule ^/?([^/]+)/([^/]+)/([^/]+)/page/ /$1/$2/$3 [L,R=301]

htaccess - redirect all requests within subdirectory, except if a requested file exists

I'm developing an app in php, and I need to set up a pretty broad .htaccess redirect. I did some reading and tried to write the RewriteConds myself, but it's a bit above my paygrade - I'm hoping someone with more experience can help. Here's what I'm trying to accomplish:
The app is contained in www.example.com/app/. Don't redirect anything above this directory.
Some files exist in this directory that will need to be accessed. Currently these are /app/includes/* and /app/sb_pages/*. This will change and expand in the future, so I need an elegant solution that encompasses all existing files. It's fine if the redirect triggers within these directories when a file isn't found - all I care about is being able to access the files within without the redirect triggering.
All other requests should be redirected to /app/index.php, with the trailing url passed in the querystring. For example, a request to /app/path1/path2/ should redirect to /app/index.php?path=path1/path2/
The redirect should not be transparent. When the user requests /app/path1/path2/, I want them to believe they have remained there. They should not see the url change to /app/index.php?path=path1/path2/.
Just for added clarity, here's a few cases to elaborate:
/app/includes/sidebar.php should not redirect.
/app/includes/nothing.html does not exist - redirect is OK
/app/path1/path2/ should redirect to /app/index.php?path=path1/path2/. User should still see their current URL as /app/path1/path2/.
I hope I've explained it clearly and pre-empted most questions. If you need clarification, please don't hesitate to ask. Thanks in advance for the help!
Try adding this to your .htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app/(.*)$ /app/index.php?path=$1 [L,QSA]
Note that if you want accesses to existing directories (as opposed to files) to also not be redirected, add a RewriteCond %{REQUEST_FILENAME} !-d above the rule.

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