mod_rewrite forward shortend URL - mod-rewrite

I am looking for a way to create a short URL path for a longer URL on my page
the long url is: domain.com/tagcloud/user.html?t=1234ABCD
i would like to offer a short version of the URL to easy access it:
domain.com/t/1234ABCD
I tried a few examples but I just don't get it how I could forward these rules.
RewriteRule ^(.*)/t/$ /tagcloud/user.html?t=$1 [L]
I am also using MODX so they already use rules.
in addition my htaccess file
RewriteEngine On
RewriteBase /
# Always use www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I must keep the code snippets above in my htaccess file. The first one simply forwards http://domain.com requests to www.domain.com
The friendly URLs part is needed to translate the internal IDs of my CMS with the alias of the URL. This feature must remain because the entire site cannot be influencted by the changes I try to make in htaccess...
I simply would like to add a listener that only if the URL matches www.domain.com/t/abcd1234
Therefore I need something that identifies the www.domain.com/t/ URL
your help is much appreciated

Try this:
RewriteCond %{REQUEST_URI} ^/t/.*
RewriteRule ^t/(.*)$ /tagcloud/user.html?t=$1 [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

Rewrite subdomain to main domain for images only using htaccess

I have a domain, where everything except image\css etc. are handled by a single php file. However after a reorganisation, alot of images have been moved from sub-domains to the main domain. So I'm looking for a way to redirect all image\css files to the main domain if they were originally on one of the sub-domains. My current code is
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.ico|\.bmp|\.css|\.ts|\.js)$
RewriteRule !^index\.php$ /index.php [L]
I've tried a couple of ways to redirect it, but I seem to break on of the existing rules, whatever I try.
Thanks
The final solution I came up with
RewriteEngine On
# Check the request isn't for the main domain
RewriteCond %{HTTP_HOST} !^domain\.com$
# Check the request is for a static resource
RewriteCond %{REQUEST_URI} \.(png|jpg|gif|jpeg|ico|bmp|css|ts|js)$
# Redirect to main domain
RewriteRule (.*) http://domain\.com/$1 [R=301,L]
# if the request isn't for index.php,
# (invisibly) redirect to index.php
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.ico|\.bmp|\.css|\.ts|\.js)$
RewriteRule !^index\.php$ /index.php [L]
For information only. As really the credit goes to jon for the answer I just tweaked it for my needs.
If the URLs in your HTML still point to the subdomains, you'll need to setup htaccess redirects on those subdomains, not on the main domain, as the requests will still be going to the subdomains.
For example in /var/www/vhosts/sub.domain.com/httpdocs/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(png|jpg|gif|jpeg|ico|bmp|css|ts|js)$
RewriteRule (.*) http://domain.com/$1 [R=301,L]
And in /var/www/vhosts/sub2.domain.com/httpdocs/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(png|jpg|gif|jpeg|ico|bmp|css|ts|js)$
RewriteRule (.*) http://domain.com/$1 [R=301,L]
UPDATE
Based on your comment that Apache handles each subdomain as if it were the main one, try this:
RewriteEngine On
# Check the request isn't for the main domain
RewriteCond %{HTTP_HOST} !(www\.)?domain\.com$
# Check the request is for a static resource
RewriteCond %{REQUEST_URI} \.(png|jpg|gif|jpeg|ico|bmp|css|ts|js)$
# Redirect to main domain
RewriteRule (.*) http://domain.com/$1 [R=301,L]

What is the solution of making dynamic subdomain like links

I have a shopping mall site built with Magento. The url is like http://exampleshopping.com
Now I have requirement where each of my users will have a vanity URL like the following -
http://abc.exampleshopping.com
http://xyz.exampleshopping.com
In the above example abc, xyz are the user names.
How is this possible without creating a sub domain from the control panel. I need this to be created automatically when a user registers.
Create an .htaccess file with the following code to build a dynamic username as subdomain.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.exampleshopping\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.exampleshopping\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?username=%1 [L]
All visits to http://username.exampleshopping.com will redirect to www.exampleshopping.com/userpage.php?username=subdomain. User only see http://username.exampleshopping.com in the address bar.
Reference : http://www.panolee.com
Use the following code in your main .htaccess file (for the www subdomain) - or in the Apache Vhost config.
Replace sonassi.com and paths to suit.
RewriteEngine On
RewriteCond %{HTTP_HOST} !www\.sonassi\.com
RewriteCond %{HTTP_HOST} ([^\.]+)\.sonassi\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?user=%1$1 [L]
You need to also create a wildcard DNS A record, if you are using cPanel, you would use
*.sonassi.com => my.ip.add.ress
Or, if you are using TinyDNS - use the following syntax
+*.sonassi.com:my.ip.add.ress:86400
Using a htaccess regex url Rewrite will work for you.

How to redirect an url with parameters?

I'm at a total loss trying to integrate a mod_rewrite in my existing page. Currently, I am building a new site from scratch, and there i have some nice clean url's such as:
http://www.example.nl/nl/example
The old site, running Cms made simple, has some not-rewritten url's that would need to be redirected to the new pages. Those url's look like this:
http://www.example.nl/index.php?page=cake-and-pie&hl=nl_NL
But shorter versions of that like:
http://www.example.nl/index.php?page=cake-and-pie
also work.
It took me a while to figure out that url's with parameters cannot simply be redirected with "Redirect 301", like i'd normaly do. So i tried some online mod_rewrite generators like this and this, but the rules outputted by those result only in 404 errors, (the redirect doesn't work at all).
My .htaccess file current looks like this:
RewriteEngine On
RewriteBase /
# remove .php;
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
The old pages would seize to exist.
How do i redirect the old pages to the new ones?
Thanks.
EDIT
RewriteCond %{QUERY_STRING} =page=pie
RewriteRule ^index\.php$ /nl/? [L,R=301]
RewriteCond %{QUERY_STRING} =page=pie&hl=nl_NL
RewriteRule ^index\.php$ /nl/? [L,R=301]
Seems to do the trick. This is of course manual for every url, but i only have a few.
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/([^/]+)/?$ index.php?page=$1&hl=$2
RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA]

Resources