I have a wordpress site and has template page. I am passing class ID as cid parameter. http://www.example.com/class-details/?cid=51
I want it to have like http://www.example.com/class-details/
I wrote rule below in .htaccess
RewriteRule ^class-details/?([^/]*)$ example.com/class-details/$1 [NC,R,L]
It leads to recursive redirection. I tried checking wordpress redirect API a lot. but no luck. Please guide me for this.
Better to create custom post type, then you don't need to pass the cid or anything and you will have Rewrite URL.
try this
<rule enabled="true" match-type="wildcard">
<from casesensitive="true">/class-details/cid=([a-zA-Z0-9]+)$</from>
<to type="passthrough">/class-details?cid=$1</to>
</rule>
Related
I'm having an issue with a rule being applied correctly on my site.
The rule is:
(^((?!\/bundles\/).)*[^\/]$)
The action is to append a slash to the end of this, using:
<action type="Redirect" url="{R:0}/" redirectType="Temporary" />
I try the following url:
http://example.com:9999/bundles/bundle.js
And IIS redirects me to http://example.com:9999/bundles/bundle.js/
But I go to IIS Manager, go to IIS Rewrite, select this rule, go to test, put the url in, click test, and it says that it's not a match.
If it's not a match, why is it still redirecting?
I created the same rule and it is redirecting. So, it is working as not expected: your rule (^((?!\/bundles\/).)*[^\/]$) match to http://example.com:9999/bundles/bundle.js
The problem in your rule. Correct rule is (^((?!bundles\/).)*[^\/]$). I removed slash before bundles. Because when request is coming into rule, it is comparing rule with path bundles/bundle.js (without starting slash)
I am in need for some HTACCESS support here. I dont believe it is very complex if I read through all the comments on similar request but simply dont get it working on my side - even after rebuilding the Permalinks.
This is my situation: I use WordPress 4.2.2 and have a theme with a portfolio. The slug of this portfolio is /portfolio/ which I want to change to /examples/
Now I have a second slug for the categories of this portfolio /PORT_CAT/ which also need to be rewritten to /example-cat/
The url is like: http://wwww.domain.com/portfolio and http://www.domain.com/port_cat/
Can somebody support me with the URL rewrite state to add to my HTACCESS and if required additional steps to rebuild the structure properly so it reflects in the front-end/browser?
Thank you in advance for the support!
This should do it, but I'm not sure why you can't change the URI in Wordpress.
RewriteEngine on
RewriteRule ^examples/?$ /portfolio/ [QSA,NC,L]
RewriteRule ^example-cat/?$ /port_cat/ [QSA,NC,L]
Currently working with an external file for URL rewrites called rewritemaps.config (following these instructions), which works great. However, we have occasion to override an entry in that file with manual entries in web.config instead and they don't appear to work.
Specifically this issue has cropped up around the use of content experiments (A/B testing) with Google, which makes heavy use of querystrings in my URLs. The querystring takes the form of:
websiteurl.com/webpage1?utm_expid=########-#&utm_referrer=http%3A%2F%2Fwebsiteurl.com%2F
Now when attempting to validate my content experiment, I get the error
Web server rejects utm_expid. Your server doesn't support added query
arguments in URLs.
...which is true for that particular URL because in the rewritemaps.config file we have this line:
<add key="/webpage1" value="/somefolder/file.aspx?id=18" />
The rewrite rule works fine but no amount of manual entries in web.config seem to work. If I comment out the line in rewritemaps.config and attempt to reach /webpage1, it errors with 404..which is expected. But I try to use manual entries in my web.config like:
<rule name="test rewrite" stopProcessing="true">
<match url="^(https?:\/\/)?websiteurl.com\/webpage1(.*)*" />
<action type="Rewrite" url="{R:1}/somefolder/file.aspx?id=18" appendQueryString="false" />
</rule>
I'm placing the rewrite rule before
<rewriteMaps configSource="rewritemaps.config" />
I've added query_string conditions, appendQueryString to true and to false, nothing is working even if I use wildcard patternSyntax, so it's leading me to believe that I can't manually add rewrite rules into the web.config if there is an external rewritemaps.config file.
Is this true? If so, how can I manually override a rewrite rule because I have to add the ability to allow a querystring in a rewrite?
Well after much consternation and research, I stumbled upon this question and the highest voted answer, and it's working for me now with the rewrite rule still in rewritemaps.config.
Changing {REQUEST_URI} to {PATH_INFO}
I wish to canonicalize a domain name, from bar.example.com to www.example.com (well anything that's not www.example.com). Site runs IIS7.
The problem is that certain URLs were of the form http://bar.example.com/asp/oldpage.asp?query=awesome, and have specific URL rewrite rules already in place that redirect to http://www.example.com/newpage/awesome
I want to write a rule that catches the other rules.
HERE'S THE CATCH: I have a lot of rules, and want to put this rule in the root of the site, but have additional rewrite/redirect rules in sub-folders, so I want to defer the 301 from happening until all the rules have been run.
Is this possible? Rewrites have an option to defer (stopProcessing="false") but this doesn't seem to be an option for Redirects.
Am I SOL here?
Unfortunately, I can confirm that the deferred processing (stopProcessing="false") works with rewrite actions only and is ignored by the redirect ones.
Should the number of matches having been small - but it is not, according to your question - I would have suggested you to combine them using a regex alternation. For example:
First match: ^first/a$
Second match: ^second/b$
Combined match: ^(first/a|second/b)$
Leading to something like:
<rule name="MyCombinedRule">
<match url="^(first/a|second/b)$" />
<action type="Redirect" url="http://www.example.com/third/c" />
</rule>
I am using urlrewriter.net and I am trying to make a redirection. So here is the condition,
If the requested url doesn't end with a / (slash) and
then add / at the end of the url and
redirect to added url.
So if the url is "http://www.something.com/cases" then add / and redirect it to "http://www.something.com/cases/"
I've used code but it didn't work out for me :
<if url="^~/(.+)(/){0}$">
<redirect url="~/(.+)" to="~/$1/$"/>
</if>
I am going to answer my own question here :
I've accomplished this by using this way :
<unless url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.aspx|\.ashx|\.ascx|\.shtml|\.html|\.htm)(\?.+)?)$">
<if url=".+(?<!/)$">
<redirect url="(.+)" to="$1/"/>
</if>
</unless>
If url doesn't end with "/" then it will be redirected to the one which has "/" at the end.
I hope it helps everyone out there.
Can you use the URL Rewrite 2.0 module? You can easily add it there, because the rewrite template for that rule is a built-into the GUI.