Include Excluded rule - phpcodesniffer

I want to include the PSR12 ruleset (which includes the rule "PSR1.Methods.CamelCapsMethodName.NotCamelCaps") but I don't want that rule to run on a specific file. so I tried the following ruleset:
<rule ref="PSR12">
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>packages/test/file</exclude-pattern>
</rule>
Unfortunately, it doesn't run the "PSR1.Methods.CamelCapsMethodName.NotCamelCaps" rule at all (also not in the rest of the code).
Does anyone know how to get this working?

As #Greg Sherwood gave the solution: I could just remove the tag from the PSR12 rule.
<rule ref="PSR12">
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>packages/test/file</exclude-pattern>
</rule>

you can also try this....
<rule ref="PSR12">
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
</rule>
The path of this You find out from
/usr/share/php/PHP/CodeSniffer/Standards/PSR1/Docs/Methods

Related

Rewrite rule IIS 8, removing .html extension

I need to add a .html file to a Wordpress installation that works on IIS.
What I have now is:
//mydomain.com/userpage.html
What I want to achieve is:
//mydomain.com/userpage/
I fixed all the other rules (pretty urls and so on...) but which code should I use to achieve the above result?
Thank you!
Max
Your rule should be like that:
<rule name="hide userpage.html">
<match url="^userpage/?$" />
<action type="Rewrite" url="/userpage.html" />
</rule>

IIS URL rewrite dynamic number of folders

I have to create a rewrite rule that catches all URLs from the old shop system and redirect them to the new shop. The problem is the following:
The source URL from the old shop can contain the path where you did find the product number, looks like this: www.domain.com/folder1/folder2/folder3/[product number].html
folder1, folder2 and folder3 can, but don't need to be in the called URL. They also are not fixed (e.g. folder1 can be "cars" or "bikes" or "services"). The link could also be just www.domain.com/folder1/[product number].html or even www.domain.com/[product number].html sometimes.
For the new system, I only need the [product number] in my target URL. Should look like this: www.domain.com/path1/path2/[product number].aspx
I could not find anything in Google or Stackoverflow that helped me with this.
Thanks in advance
Daniel
This should work:
<system.webServer>
<rewrite>
<rules>
<rule name="Three deep" stopProcessing="true">
<match url=".*/.*/.*/(.*?).html" />
<action type="Redirect" url="/path1/path2/{R:1}.aspx" />
</rule>
<rule name="Two deep" stopProcessing="true">
<match url=".*/.*/(.*?).html" />
<action type="Redirect" url="/path1/path2/{R:1}.aspx" />
</rule>
<rule name="One deep" stopProcessing="true">
<match url=".*/(.*?).html" />
<action type="Rewrite" url="/path1/path2/{R:1}.aspx" />
</rule>
<rule name="None deep" stopProcessing="true">
<match url="(.*?).html" />
<action type="Rewrite" url="/path1/path2/{R:1}.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
I am worried that the expression - (.*?) - I'm using for the product code is too catch all, but I don't know the structure of your product codes. If you could tighten it up, it'd be better.
I'm also worried that they will hit things that aren't products (e.g. category and search) so if there is a pivot point that all product URLs use, I'd recomend using that. Tightening the product code bit will probably help false matches too.
At the moment it's working on the .html vs .aspx being the bit that isn't sending it into a redirect spiral.
I can probably do it in less rules with a better regex, which I'll have a bash at tonight.

IIS Redirect Regex doesn't work with a space - %20 in URL

So I have one simple problem but somehow doesnt seem to work. I have one URL http://www.domain.com/%20#axzz2ZX4J0KAS which I want to redirect to http://www.domain.com/page-name.htm. I have tried so many combinations in IIS URL Rewrite/web.config and they all seem to work inside test pattern dialog but none works in browsers.
1.
<rule name="Redirect%20InHomePage" enabled="true" stopProcessing="true">
<match url="^(.+)domain\.com/(\s|%20)(.+)" ignoreCase="true" />
<action type="Redirect" url="http://www.domain.com/page-name.htm" />
</rule>
2.
<match url="(.+)/%20(.+)" ignoreCase="true" />
3.
<match url="(.+)domain.com/ (.+)" ignoreCase="true" />
4.
<match url="(.+)domain.com/(\s|%20)(.+)" ignoreCase="true" />
As you can see I tried all of above patterns, they all work fine in Test Pattern dialog but when i browse URL, it always converts %20 to space and rule doesn't work for redirect.
Please help me for this simple yet unsolved problem, if anyone knows what am I missing.
I was having a similar issue and got it to work by typing spaces " " instead of %20 for my rules.
So here you may want to try [ ] for your space.
http://imgur.com/6sjWVjL
Don't include the domain name in your match url.
If you want to handle either having the tracking code or not in your url then you probably want to use something like this:
<rule name="RedirectSpaceInHomePage" stopProcessing="true">
<match url="^\s(#\.*)?$" />
<action type="Redirect" url="page-name.htm" />
</rule>

IIS url rewrite | How to remove directory and extension?

I have been struggling with the following for quite some time now:
Default url:
examplesite.com/folder/about.cshtml
Desired url:
examplesite.com/about
Basically I want to accomplish two things:
1 Remove the file extension with realtively compact code.
2 Remove the folder that houses the about page.
I have found some uncommon rules to achieve all the above, but they mostly contain a lot of redundant code that crashes my site when I test it with IIS 8.0.
So I was hoping someone could share a rule that is compact and fits my needs. Or seperate rules with the same outcome.
Every contribution is much appreciated :)
I'm not certain I entirely understand your needs, but here's something that's at least close. It strips out the first folder and file extension (so examplesite.com/folder/about.cshtml becomes examplesite.com/about and examplesite.com/folder/help/about.cshtml becomes examplesite.com/help/about). If you wanted to strip all folders then just remove the ?.
<rule name="Remove Directory and Extension">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Rewrite" url="{R:2}" />
</rule>
Update:
Ok, I think what you want is a combination of two rules then:
<rules>
<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="folder/{R:0}.cshtml" />
</rule>
</rules>
The first rule makes sure that all requests are to friendly URLs. The second takes the friendly URL and rewrites it to your physical path, where the physical path is folder/[FRIENDLY_PATH].cshtml.

Need help for regex design in system.webServer rewrite rule in web.config

I am redirecting a lot of old pages because of a new webdesign. However I have run into one little issue.
I want to redirect:
www.domainname.com/Default.aspx
But not redirect
www.domainname.com/somesub/Default.aspx
I need it written like this:
<rule name="301 Redirect Default">
<match url="???????" />
<action type="Redirect" url="http://www.domainname.com/index.php" redirectType="Permanent" />
</rule>
Where the questionmarks mark the regex I need.
Can anyone help?
Cheers
How about
<match url="^Default\.aspx" />
Also see e.g. this article regarding IIS rewrite rules.

Resources