How to exclude ajax from htaccess? - ajax

I'm trying to force trailling slash in my site. I have found the bellow code that it works but it causes problem with ajax code.
This is my htaccess code
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
So now I want to exclude the ajax from this or I if we can exclude a specific url that uses ajax.
e.g. my-site.com/onepage

To exclude /onepage you can use a negitive RewriteCond :
RewriteCond %{REQUEST_URI} !/onepage
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

Related

Rewrite AEM index.html

There is a rewrite issue in apache 2.4
I am trying to do the following steps but failing.
I want the result as -
If i hit url/index.html at apache(dispatcher)it should redirect and map to /content/company/en_US/index.html at AEM publisher but it should not show the long URL. Also same time all the long urls should be shortened as per second rule. Due to this conflict if i hit the url it is going to infinte loop redirects.
Also please note if AEM publisher finds /index.html it will redirect to /content.html i.e the root mapping. So i need to mask /index.html and map the same to long url without showing the long url.
Rule 1 :#rewrite "/index.html" home page
RewriteCond %{REQUEST_URI} ^/index.html$
RewriteRule ^/index.html$ /content/company/en_US/index.html [PT,L]
Rule 2 :
#shorten all long URLs
RewriteRule ^/content/company/en_US/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
Kindly provide your inputs.
RewriteEngine On
RewriteRule ^/index.html /content/company/en_US/index.html [PT,L]
RewriteCond %{REQUEST_URI} !^/apps
RewriteCond %{REQUEST_URI} !^/bin
RewriteCond %{REQUEST_URI} !^/content
RewriteCond %{REQUEST_URI} !^/etc
RewriteCond %{REQUEST_URI} !^/home
RewriteCond %{REQUEST_URI} !^/libs
RewriteCond %{REQUEST_URI} !^/tmp
RewriteCond %{REQUEST_URI} !^/var
RewriteRule ^/(.*)$ //content/company/en_US/$1 [PT,L]
Try like this it will work and please share your etc map node structure.

IBM Commerce SEO URL issue with Ajax calls

i am using WCS7 FEP7. i just enabled seo following below steps.
httpd.conf changes
RewriteRule ^/(.*)$ /webapp/wcs/stores/servlet/$1 [PT,NC]
wc-server.xml changes
<SEOConfiguration defaultUrl="" dynamicUrl="true" enable="true">
<context-root-rewrite value="/"/>
</SEOConfiguration>
I have run the keyword generation job..All SEO URLs are coming up nice.but OOB ajax calls are failing.
Add to cart ajax calling is failing..
I see http:///AjaxOrderChangeServiceItemAdd Ajax POST call is being triggered..
I am getting 404 error.
Where as Commerce server needs http:///webapp/wcs/stores/servlet/AjaxOrderChangeServiceItemAdd
I tried to put a rewrite rule to add 'webapp/wcs/stores/servlet' for this particular request..As this is a POST call (parameters in the body), it would not work properly.
RewriteRule /AjaxOrderChangeServiceItemAdd$
/webapp/wcs/stores/servlet/AjaxOrderChangeServiceItemAdd?data=$1
[NC,L]‹
Am i missing something here.?
Please help.
Try this..In the code snipped below, you need to pass your store and catalog ids respectively.
RewriteEngine on
RewriteRule ^/?$ /webapp/wcs/stores/servlet/TopCategoriesDisplay?storeId=<storeId>&catalogId=<catalogId> [L,QSA,PT]
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteCond %{REQUEST_URI} !^/sitemap.xml(.gz)?$
RewriteCond %{REQUEST_URI} !^/solr.*$
RewriteCond %{REQUEST_URI} !^/lobtools.*$
RewriteCond %{REQUEST_URI} !^(/)?$
RewriteCond %{REQUEST_URI} !^/webapp.*$
RewriteCond %{REQUEST_URI} !^/wcsstore.*$
RewriteCond %{REQUEST_URI} !^/ConsumerDirectStorefrontAssetStore.*$
RewriteCond %{REQUEST_URI} !^/wps.*$
RewriteCond %{REQUEST_URI} !^/images/.*$
RewriteCond %{REQUEST_URI} !^/favicon\.ico
RewriteRule ^/(.*) /webapp/wcs/stores/servlet/$1?storeId=<storeId>[QSA,PT]
read this below and try it , it is a little different than what you did
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.starterstores.doc/tasks/tsmshortenmadisonsurl.htm
As it's mentioned in
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.starterstores.doc/tasks/tsmshortenmadisonsurl.htm
`If you are specifying a blank context root, use the following format instead:
RewriteEngine on
RewriteRule ^/(?!wcsstore)(.*) /webapp/wcs/stores/servlet/$1 [PT,L]`
The SEO engine should not care if it's an POST request. Data is sent regardless.
Be sure that you've created your AJAX call from wcf:url
http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.component-services.doc/refs/rwvwcfurl.htm

RewriteCond %{REQUEST_URI} not working

I am trying to redirect all requests coming in to the web server as http://portal.company.com/legacy to http://portal.company.com/wps/portal/public/legacy/legacyportlet with the following rule, but it is not working as expected.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^portal\.company\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/legacy$ [NC]
RewriteRule ^(.*)$ /wps/portal/public/legacy/legacyportlet$1 [NC,L,PT]
I have also tried
RewriteCond %{HTTP_HOST} ^portal\.company\.com$ [NC]
RewriteRule ^/legacy /wps/portal/public/legacy/legacyportlet [NC,L,PT]
Any help would be greatly appreciated!
Thanks
It doesn't look like your source or target URLs change in any way, so possibly you're better off using Apache's basic Redirect directive which just redirects one URL to another.
Use this rule:
RewriteCond %{HTTP_HOST} ^portal\.company\.com$ [NC]
RewriteRule ^legacy/?$ /wps/portal/public/legacy/legacyportlet [NC,L]
Remember that in .htaccess RewriteRule doesn't match leading slash of URI.

double slash apache configuration

i'm deploying a ror application and now i have to rewrite the url (in apache) to
add a prefix www to the url
add / to the end of the url
So i took the following approach:
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^foo\.com
RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L]
The problem is that it is appending two trailing slash to my url
So for example a resource /question/ask are becoming:
http://foo.com//question/ask
I tried to add the following Rule before all my Rewrite rules to try to remove the double //:
RewriteCond %{REQUEST_URI} ^//
RewriteRule ([^/]*)/+(.*) http://www.foo.com/$1/$2 [R=301,L]
but it didnt work.. any idea to rip off all extras "//" added to the url?
The $1 will include a / at the beginning. You probably want
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^foo\.com
RewriteRule ^(.*)$ http://www.foo.com$1 [R=301,L]

How do I write a custom mod_rewrite .htaccess file for CakePHP routing?

I've rewritten my web app using CakePHP, but now I need to have my old formatted urls redirect to my new url format. I can't seem to add my own custom mod rewrite rule. I've added it above the main cakephp rewrite rule, but I'm getting an infinite redirect loop. I just want http://mysite.com/index.php?action=showstream&nickname=user to redirect to http://mysite.com/user before the cakephp rewrite happens.
EDIT: Ok, so now when the condition is met it's redirecting but it's appending the original query string to the end. I'm assuming that's due to the QSA flag in CakePHP rewrite rules, but I was under the impression the "L" in my rule would stop that from executing...
RewriteEngine On
RewriteCond %{QUERY_STRING} ^action\=showstream&nickname\=(.*)$
RewriteRule ^.*$ http://mysite.com/%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
When you do a capture inside the RewriteCond line instead of the RewriteRule, you have to reference the capture with %N instead of $N. That is, your RewriteRule line should be:
RewriteRule ^index.php$ /%1 [R=301,L]
Try to test the request line (THE_REQUEST) to see what URI originally has been requested:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php
RewriteCond %{QUERY_STRING} ^action=showstream&nickname=([^&]*)$
RewriteRule ^index\.php$ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?url=$0 [QSA,L]
But maybe it would be easier to do this with PHP.

Resources